function createRandomPassword ( hashLen:uint, includeLowercase:Boolean = true, includeNumbers:Boolean = true, includeUppercase:Boolean = false ) :String |
{ |
var strHash: |
String = ""; |
if ( includeLowercase ) strHash += "abchefghjkmnpqrstuvwxyz"; |
if ( includeNumbers ) strHash += "0123456789"; |
if ( includeUppercase ) strHash += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
var maskPick: |
Number; |
var passwordStr: |
String = ""; |
var maskLen: |
uint = strHash.length; |
for ( var i:uint = 0; i < hashLen; i++ ) |
{ |
maskPick = Math.floor ( Math.random() * maskLen ); |
passwordStr += strHash.charAt ( maskPick ); |
} |
return passwordStr; |
} |
trace ( createRandomPassword ( 8 ) ); |
// Output |
// 6k3x10h8j |
trace ( createRandomPassword ( 6, true, true, true ) ); |
// Output |
// D2jHEfT |
trace ( createRandomPassword ( 16, false, true, true ) ); |
// Output |
// O8I2DTSLHHWRI50Z |
trace ( createRandomPassword ( 16, true, false, false ) ); |
// Output |
// xxfeyshhqkrsqvhjt |
trace ( createRandomPassword ( 16, false, false, true ) ); |
// Output |
// XMXIDTIXMNGNUXZT |
trace ( createRandomPassword ( 16, false, true, false ) ); |
// Output |
// 4026352375069424 |