| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|
#1 (permalink) |
|
Unregistered
Posts: n/a
|
hi friends
I want to know How can i Create the 7 digit AlfaNumeric Password which will be unique for every user? Plz give me Answer my id is Singh_dharmendra2001@Yahoo.co.in. |
|
| The Following User Says Thank You to For This Useful Post: |
Dharmendra Singh (21-09-06)
|
|
|
#2 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 78 Times in 63 Posts Thanks: 57
Thanked 78 Times in 63 Posts
Rep Power: 17
|
Re: how can i create the 7 digit AlfaNumeric Password .
Hi Dharmendhra,
Probably this could help you , i wrote a program which generates a password randomly, but it generates only numeric password. pls try to enhance it which meets your requirements import java.util.Date; import java.util.Random; public class PasswordGenerator { private Random rng = null; public PasswordGenerator(){ rng = new Random((new Date()).getTime()); } public String generatePassword() { StringBuffer buff = new StringBuffer(); while (buff.length() < 8) { buff.append(Math.abs(rng.nextInt())); } return buff.substring(0, 7); } public static void main(String args[]) { PasswordGenerator pg = new PasswordGenerator(); System.out.println("Generated Password:"+pg.generatePassword()); } } It is a compiled code and executing fine If u need any help, post a reply again Thanks Mohan.T
__________________
M0h@n |
|
|
|
| The Following User Says Thank You to t_mohan For This Useful Post: |
Dharmendra Singh (21-09-06)
|
|
|
#3 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 78 Times in 63 Posts Thanks: 57
Thanked 78 Times in 63 Posts
Rep Power: 17
|
Re: how can i create the 7 digit AlfaNumeric Password .
Hi Dharmendra
This is the code, which generates Random Password with alpha-numeric characters Please feel free to ask me if you have any questions import java.util.Date; import java.util.Random; import java.security.SecureRandom; public class PasswordGenerator { protected SecureRandom rand; protected char[] firstAlphabet; protected char[] lastAlphabet; protected char[] alphabet; public PasswordGenerator(){ rand = new SecureRandom(); } public String generatePassword(char[] printableAlphabets) { String generatedPassword = new String(getPasswordChars(printableAlphabets)); return generatedPassword.substring(0,7); } public char[] getPasswordChars(char[] pass){ int length = pass.length; for (int i=0; i if (i == 0 && firstAlphabet != null){ useAlph = firstAlphabet; } else if (i == length - 1 && lastAlphabet != null){ useAlph = lastAlphabet; } int size = avoidRepetition(useAlph, pass, i, 2, useAlph.length); pass[i] = useAlph[rand.nextInt(size)]; } return(pass); } private static int avoidRepetition(char[] alph, char[] pass, int passSize, int repetition, int alphSize){ if (repetition > -1){ int repPos = 0; while ((repPos = findRepetitions(pass, repPos, passSize, repetition)) != -1){ alphSize -= moveChars(alph, alphSize, pass[repPos+repetition]); repPos++; } if (alphSize == 0) alphSize = alph.length; } return alphSize; } private static int findRepetitions(char[] pass, int start, int end, int length){ for (int i=start; i for (int j=0; onTrack && j } if(onTrack) return i; } return -1; } private static int moveChars(char[] alph, int numGood, char c){ int count = 0; for (int i=0; i numGood--; char temp = alph[numGood]; alph[numGood] = alph[i]; alph[i] = temp; count++; } } return count; } public void setFirstAlphabet(char[] alphabet){ if (alphabet == null || alphabet.length == 0){ this.firstAlphabet = null; } else { this.firstAlphabet = alphabet; } } public void setLastAlphabet(char[] alphabet){ if (alphabet == null || alphabet.length == 0){ this.lastAlphabet = null; } else { this.lastAlphabet = alphabet; } } public void setAlphabet(char[] alphabet){ if (alphabet == null) throw new NullPointerException("Null alphabet"); if (alphabet.length == 0) throw new ArrayIndexOutOfBoundsException("No characters in alphabet"); this.alphabet = alphabet; } public static void main(String args[]) { final char[] PRINTABLE_ALPHABET = { '0','1','2','3','4','5','6','7','8', '9','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', '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',}; PasswordGenerator pg = new PasswordGenerator(); pg.setAlphabet(PRINTABLE_ALPHABET); pg.setFirstAlphabet(PRINTABLE_ALPHABET); pg.setLastAlphabet(PRINTABLE_ALPHABET); System.out.println("Generated Password:"+pg.generatePassword(PRINTABLE_ALPHABET)); } }
__________________
M0h@n |
|
|
|
| The Following User Says Thank You to t_mohan For This Useful Post: |
Dharmendra Singh (21-09-06)
|
|
|
#5 (permalink) | |
|
Junior Member
Join Date: Sep 2006
Posts: 24
Thanks: 7 Thanked 0 Times in 0 Posts Thanks: 7
Thanked 0 Times in 0 Posts
Rep Power: 3
|
Re: how can i create the 7 digit AlfaNumeric Password .
Quote:
Last edited by Dharmendra Singh; 21-09-06 at 01:05 PM. |
|
|
|
|
|
|
#6 (permalink) |
|
Junior Member
Join Date: Sep 2006
Posts: 24
Thanks: 7 Thanked 0 Times in 0 Posts Thanks: 7
Thanked 0 Times in 0 Posts
Rep Power: 3
|
Re: how can i create the 7 digit AlfaNumeric Password .
Hi Mohan.T
Your code for generate the AlfaNumeric Password is not compile it is showing the error.plz send me compile code.i m waiting ur reply. Thanks Dharmendra singh |
|
|
|
|
|
#7 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 78 Times in 63 Posts Thanks: 57
Thanked 78 Times in 63 Posts
Rep Power: 17
|
Re: how can i create the 7 digit AlfaNumeric Password .
Hi Dharmendra,
I dont know how it has missed some of the text while copying . i wrote my code and compiled it and tested. After making sure it is working i copied it on the forum. anyway i sent u the code to ur mail id. Pls find the attached File in ur mail box singh_dharmendra2001@yahoo.co.in from mohan.thutta@gmail.com Thank You Mohan.T
__________________
M0h@n Last edited by t_mohan; 22-09-06 at 07:40 PM. |
|
|
|
|
|
#8 (permalink) |
|
Junior Member
Join Date: Feb 2007
Age: 28
Posts: 17
Thanks: 1 Thanked 0 Times in 0 Posts Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 2
|
how to retrieve contents from particular site
Hi ,
i am getting one problem tha is "i want to retrieve the contents from any web page into my own page,so how can i retrieve the contents of the web page,and how can i display multiple windows in my own page and every window should refresh for every 30 sec ,could u tell me plzzz |
|
|
|
|
|
#9 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 78 Times in 63 Posts Thanks: 57
Thanked 78 Times in 63 Posts
Rep Power: 17
|
Re: how to retrieve contents from particular site
I couldnot understand ur question krishna,pls be clear then probably i can help you.
__________________
M0h@n |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| WHAT IS CONNECTION POOLING? | yathish | JAVA Technologies | 10 | 19-09-06 02:39 PM |
| Removing password protection from PDF documents | vjsreevs | Latest Tech News & Innovations | 0 | 11-06-06 03:43 PM |