Flex Random Password Generator
Here’s a nice static method for creating random passwords…should the need ever arise
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public static function generateRandomPassword( length:int = 7 ) : String { //characters to use in password var _salt : String = "abchefghjkmnpqrstuvwxyz0123456789ABCHEFGHJKMNPQRSTUVWXYZ"; //initialize vars var _password : String = ''; var _i:Number = 0; //loop while ( _i <= length ) { var _num : Number = Math.random() * _salt.length; _password += _salt.charAt( _num ); _i++; } return _password; } |
Enjoy!
Categories: Adobe Flash, Adobe Flex

hi there
thanks for the code.
i have tried this but it does not seem to work. nothing is displayed. even when i put trace(_password) immediately after line 18.
i am using flash builder and i created a new project and pasted this code. i also put the creationComplete= “generateRandomPassword()”
i bet im doing something wrong. can you please provide some hints? im a newbie.
Nice Tips!!
Its a Very Important program , i used it in my Project!!
thanks
Affordable Website Designing
Nice. Couple suggestions:
I’m not sure ‘salt’ is the right name for that variable. It’s more of a list of potential characters; ‘salt’ implies that some sort of cryptographic operation is going on.
I see you took out some characters to avoid confusion; I’d take out more. I’d removed all the vowels, so you don’t accidentally generate rude words, and I’d also take out the number ’1′, which can easily be confused with the lower case ‘L’ in some fonts. (I know you don’t have the lowercase ‘L’ in the potential characters, but the user won’t know that when they’re staring at their generated password).
@james
The problem why u were not seeing the trace statement is, because the statement was after the return code. Try putting the trace before the return command. Also the ‘generateRandomPassword’ function returns the password of datatype string, so try assigning it to a variable to use it. Just using creationcomplete=’generateRandomPassword is useless