open the visual studio
select the new website
After that copy and paste the following code in aspx page<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form2" runat="server">
<div>
<asp:Button ID="btnpassword" runat="server" onclick="btnpassword_Click" Text="Generate Password" />
</div>
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>
---------------------------------------------------------------------------------------------------
After that open the aspx.cs file before copy and paste the code declare the two variables globally
--------------------------------------------------------------------------------------------------
Protected Sub btnpassword_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim password As String = generatePassword(10)
Label1.Text = password
End Sub
----------------------------------------------------------------------------------------------------------------
Private Function generatePassword(ByVal length As Integer) As String
Dim randomNumber As Integer
Dim i As Integer = 1
Dim strTemp As String
While i <= length
randomNumber = objRandom.[Next](1, 30)
strTemp = DirectCast(Microsoft.VisualBasic.Interaction.Choose(randomNumber, "B", "!", "D", "2", "F", _
"3", "$", "4", "a", "5", "j", _
"6", "K", "7", "L", "8", "m", _
"9", "N", "p", "@", "X", "Y", _
"#", "G", "H", "%", "R", "w"), String)
strPassword += strTemp
i += 1
End While
Return strPassword
End Function
Dim password As String = generatePassword(10)
Label1.Text = password
End Sub
----------------------------------------------------------------------------------------------------------------
Private Function generatePassword(ByVal length As Integer) As String
Dim randomNumber As Integer
Dim i As Integer = 1
Dim strTemp As String
While i <= length
randomNumber = objRandom.[Next](1, 30)
strTemp = DirectCast(Microsoft.VisualBasic.Interaction.Choose(randomNumber, "B", "!", "D", "2", "F", _
"3", "$", "4", "a", "5", "j", _
"6", "K", "7", "L", "8", "m", _
"9", "N", "p", "@", "X", "Y", _
"#", "G", "H", "%", "R", "w"), String)
strPassword += strTemp
i += 1
End While
Return strPassword
End Function
No comments:
Post a Comment