Results 1 to 6 of 6
  1. #1
    qwerty53's Avatar
    qwerty53 is offline Member
    Join Date
    Jul 2011
    Posts
    32
    Rep Power
    0

    Unhappy Strong passwords with Java

    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 ???

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    We can, but why don't you show what you have tried first? This is surprisingly easy to do, just do some thinking.

  3. #3
    qwerty53's Avatar
    qwerty53 is offline Member
    Join Date
    Jul 2011
    Posts
    32
    Rep Power
    0

    Default

    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 11:37 AM.

  4. #4
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    @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.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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
    Java 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.
    Java 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

    Java Code:
    String s;
    do{
      generate password
    }while(test password);

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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

  1. Ready to Program JAVA - passwords
    By terrytran in forum New To Java
    Replies: 6
    Last Post: 06-14-2011, 03:12 PM
  2. WiKID Strong Authentication System 3.0.2
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-02-2008, 08:12 PM
  3. Strong Java Architect, Madison, WI
    By ITREC in forum Jobs Offered
    Replies: 0
    Last Post: 06-30-2008, 09:56 PM
  4. Replies: 0
    Last Post: 12-15-2007, 09:29 AM
  5. WiKID Strong Authentication System 3.0.7
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-16-2007, 05:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •