Generate the Password Randomly

Just follow the below code tp generate the password character randomly....
Step:1 just drag a text box into the form
Step:2 Just Drag a Button into the form

Step3: write the below method
VB.NET Code
Private Function GenerateRandomNo()
Dim s As String="kkdskkds87430900403kdsjj88ds88899d9sefghijkmnopqrstuvwxyzABCDEFrer"
Dim rand As New Random
Dim count As Integer = s.Length
Dim arr As Char() = New Char(6) {} 'defined the array
For i As Integer = 0 To 6 'array length
arr(i) = s(s.Length * rand.NextDouble)
Next
Return New String(arr)
End Function

Step 4:click the button
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
TextBox1.Text = GenerateRandomNo()
End Sub

C#.Net Code
public class frmRandomPassGen
{
//generate the password Randomly
private object GenerateRandomNo()
{
//just define some
string s = "hdaskkdskkds87430900499d9sefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRST";
Random rand = new Random();
int count = s.Length;
char[] arr = new char[7];
//defined the array
//array length
for (int i = 0; i <= 6; i++) {
arr[i] = s[s.Length * rand.NextDouble()];
}
return new string(arr);
}

private void btnGenerate_Click(System.Object sender, System.EventArgs e)
{
TextBox1.Text = GenerateRandomNo();
}
}

No comments:

Post a Comment