Results 1 to 6 of 6
Thread: Strong passwords with Java
- 07-13-2011, 09:14 AM #1
- 07-13-2011, 09:25 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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, 09:46 AM #3
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 ?
Java 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]); }Last edited by qwerty53; 07-13-2011 at 10:37 AM.
- 07-13-2011, 10:43 AM #4
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
@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.
- 07-13-2011, 10:52 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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
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.Java Code:return new StringBuilder(word).reverse().toString().equals(word);
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.
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.Java Code:String[] x = "a b c d e f g h i j k ... x y z".split();
Finally, the easiest way to do validification is with a loop
Java Code:String s; do{ generate password }while(test password);
- 07-13-2011, 11:54 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
Similar Threads
-
Ready to Program JAVA - passwords
By terrytran in forum New To JavaReplies: 6Last Post: 06-14-2011, 02:12 PM -
WiKID Strong Authentication System 3.0.2
By Java Tip in forum Java SoftwareReplies: 0Last Post: 07-02-2008, 07:12 PM -
Strong Java Architect, Madison, WI
By ITREC in forum Jobs OfferedReplies: 0Last Post: 06-30-2008, 08:56 PM -
Pls help with a project. About doing passwords. Thanks
By saytri in forum New To JavaReplies: 0Last Post: 12-15-2007, 08:29 AM -
WiKID Strong Authentication System 3.0.7
By levent in forum Java SoftwareReplies: 0Last Post: 05-16-2007, 04:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks