|
-
May 24th, 2004, 02:51 PM
#1
Thread Starter
Lively Member
generate passwords
Does anybody have code to randomly generate passwords?? I would like something either 6 or 8 digit alphnumeric. Its being used for people to register for a site and the site will generate the password. So the first time the person logs in they are forced to change it.
Thanks
-
May 24th, 2004, 03:35 PM
#2
Fanatic Member
Threw this together - I know it's in C# but the basic functionality should be pretty starightforward. Let me know if you need some tranlation.
Code:
private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text="";
StringBuilder sb=new StringBuilder();
Random character=new Random();
Random charNum=new Random();
for(int i=0;i<7;i++)
{
if(charNum.Next(2)==1)
{
sb.Append(FindLetter(character.Next(26)));
}
else
{
sb.Append(character.Next(26).ToString());
}
}
textBox1.Text=sb.ToString();
}
private string FindLetter(int i)
{
string rtn="";
switch(i)
{
case 1:
rtn="a";
break;
case 2:
rtn="b";
break;
case 3:
rtn="c";
break;
case 4:
rtn="d";
break;
case 5:
rtn="e";
break;
case 6:
rtn="f";
break;
case 7:
rtn="g";
break;
case 8:
rtn="h";
break;
case 9:
rtn="i";
break;
case 10:
rtn="j";
break;
case 11:
rtn="k";
break;
case 12:
rtn="l";
break;
case 13:
rtn="m";
break;
case 14:
rtn="n";
break;
case 15:
rtn="o";
break;
case 16:
rtn="p";
break;
case 17:
rtn="q";
break;
case 18:
rtn="r";
break;
case 19:
rtn="s";
break;
case 20:
rtn="t";
break;
case 21:
rtn="u";
break;
case 22:
rtn="v";
break;
case 23:
rtn="w";
break;
case 24:
rtn="x";
break;
case 25:
rtn="y";
break;
case 26:
rtn="z";
break;
}
return rtn;
}
-
May 24th, 2004, 03:40 PM
#3
Hyperactive Member
you could just do somehting like this
VB Code:
Dim pass As String
Dim passChar As Char
For i = 1 To 8
Randomize()
If Int(Rnd() * 2) = 0 Then
passChar = Chr((Rnd() * (57 - 48)) + 48)
Else
passChar = Chr((Rnd() * (90 - 65)) + 65)
End If
pass &= passChar
Next
-
May 25th, 2004, 08:39 AM
#4
Hyperactive Member
I have a project that generates strong passwords that contain mixed case letters, numbers and special characters. The length of the password, number of caps, numbers and special characters can all be controlled.
Email me if you are interested.
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|