Ever wanted to create or generate passwords within Adobe Flex / Flash Builder or AS3 ?

Well it’s quite simple to do this.

You only need 11 lines of code for generating a password (well 13 if you count the function statement)

With this piece of code you can create any kind of password for your user.

public function createpw(strHash:String = 'abchefghjkmnpqrstuvwxyz0123456789',lnHash:Number = 5):String
{
	var i:Number = 0;
	var hash:String = "";
	var nLenght:Number = strHash.length;
	while (i <= lnHash)
	{
		var num:Number = Math.round(Math.random()*nLenght);
		hash += strHash.charAt(num);
		i++;
	}
	return hash;
}

createpw () function call examples:


If you want createpw() to create a 5 letter password

txtField.text = createpw();


if you want createpw() to create a 4 digit password

txtField.text = createpw(‘1234567890’, 4);


if you want createpw() to generate 12 any character password

txtField.text = createpw('acbdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()', 12);


if you want createpw() to create a 8 any character password with upper and lower case characters

txtField.text = createpw('acbdefghijklmnopqrstuvwxyzACBDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()', 8);

VN:F [1.9.3_1094]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Flex AS3 Password Creator / Generator, 10.0 out of 10 based on 1 rating

One Response to “Flex AS3 Password Creator / Generator”

  • Merso Maniac:

    To avoid an empty string one must change

    var num:Number = Math.round(Math.random()*nLenght);

    to

    var num:Number = Math.floor(Math.random()*nLenght);

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: +1 (from 1 vote)

Leave a Reply

QR Code
Donate

Like the information on my site? Please donate for a cup of coffee, or give a bit more for a cappuccino.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes