• 07-13-2011, 10:14 AM
qwerty53
Using with these characters ("a,b,c...,x,y,z and 0,1,2...,9") and generating random passwords

* it can't be palindrome...
* three and more characters can't be the same...
* totally i have to use 8 characters or numbers..

Can you help me ???
• 07-13-2011, 10:25 AM
sunde887
We can, but why don't you show what you have tried first? This is surprisingly easy to do, just do some thinking.
• 07-13-2011, 10:46 AM
qwerty53
there are palindrome test and random password generator and how to use them together ? and how to test three or more characters are the same ?

Code:

```            public static boolean isPalindrome(String word) {     int left  = 0;                    int right = word.length() -1;        while (left < right) {                if (word.charAt(left) != word.charAt(right)) {             return false;                }         left++;                            right--;                      }       return true;                  }                 Random r= new Random();                 String arr[]={"1","2","3","4","5","6","7","8","9","0","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};                 int p;                 for (int i=1;i<=8;i++)                 {                         p=r.nextInt(36);                         System.out.print(arr[p]);                 }```
• 07-13-2011, 11:43 AM
acmohan
@qwerty53: you have every thing in your hand just it try out. create a random password, pass that password to that check palindrome and check for repeated characters.:(grin):
• 07-13-2011, 11:52 AM
sunde887
A few tips, your palindrome code works, but it would be much simpler to just use a stringbuilder. The whole method can be made into one line
Code:

`return new StringBuilder(word).reverse().toString().equals(word);`
I'm spoon-feeding a bit with this but you put in the effort of the original so I figured I'd show you alternate approach. Obviously you can make it multiple lines by storing a reference to the reversed string, then performing comparisons.

Next, it may be easier to fill your array with a log string of characters followed by spaces, and then splitting it. It's really no different but it is another approach to be mindful of.
Code:

`String[] x = "a b c d e f g h i j k ... x y z".split();`
Next, don't hardcore the random generated number, instead use the length of the array, this way if you decide to add characters to the choices you don't need to increase the randomly generated number.

Finally, the easiest way to do validification is with a loop

Code:

```String s; do{   generate password }while(test password);```
• 07-13-2011, 12:54 PM
sunde887
Post progress here rather than pm(I don't mind pm's but you will get more help this way), you want two distinct functions, one to take a string input and determine whether or not it is a palindrome and one to generate a password. The generating password should do a password generation, then test it. Rather than use the idea to print the generated password, you should use string concatenation.