•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 426,565 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,688 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 9462 | Replies: 4
![]() |
•
•
Join Date: Jun 2005
Posts: 50
Reputation:
Rep Power: 4
Solved Threads: 0
I have created a random password generator function in asp.net (vb.net). How do i call this function through my asp.net button???
:cry:
Function RandomPW(ByVal myLength)
'These constant are the minimum and maximum length for random
'length passwords. Adjust these values to your needs.
Const minLength = 6
Const maxLength = 20
Dim X, Y, strPW
If myLength = 0 Then
Randomize()
myLength = Int((maxLength * Rnd()) + minLength)
End If
For X = 1 To myLength
'Randomize the type of this character
Y = Int((3 * Rnd()) + 1) '(1) Numeric, (2) Uppercase, (3) Lowercase
Select Case Y
Case 1
'Numeric character
Randomize()
strPW = strPW & Chr(Int((9 * Rnd()) + 48))
Case 2
'Uppercase character
Randomize()
strPW = strPW & Chr(Int((25 * Rnd()) + 65))
Case 3
'Lowercase character
Randomize()
strPW = strPW & Chr(Int((25 * Rnd()) + 97))
End Select
Next
RandomPW = strPW
End Function
:cry:
Function RandomPW(ByVal myLength)
'These constant are the minimum and maximum length for random
'length passwords. Adjust these values to your needs.
Const minLength = 6
Const maxLength = 20
Dim X, Y, strPW
If myLength = 0 Then
Randomize()
myLength = Int((maxLength * Rnd()) + minLength)
End If
For X = 1 To myLength
'Randomize the type of this character
Y = Int((3 * Rnd()) + 1) '(1) Numeric, (2) Uppercase, (3) Lowercase
Select Case Y
Case 1
'Numeric character
Randomize()
strPW = strPW & Chr(Int((9 * Rnd()) + 48))
Case 2
'Uppercase character
Randomize()
strPW = strPW & Chr(Int((25 * Rnd()) + 65))
Case 3
'Lowercase character
Randomize()
strPW = strPW & Chr(Int((25 * Rnd()) + 97))
End Select
Next
RandomPW = strPW
End Function
•
•
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation:
Rep Power: 3
Solved Threads: 10
make it a static function in a class (say Utilities) then in your click event in code behind just call Utilities.RandomPW(7). But you need to return the password you generated.
No you copied it without understanding it again. There is no way that you could have thought up that code and coded it and then not know how to call a function.
•
•
•
•
I have created a random password generator function in asp.net (vb.net)
•
•
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation:
Rep Power: 4
Solved Threads: 19
here ya go hope this helps
WebForm1.aspx
WebForm1.aspx
WebForm1.aspx
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="vbtest.WebForm1"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>WebForm1</title> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form runat=server id="Form1"> <asp:Button id="RndPassword" style="Z-INDEX: 100; LEFT: 392px; POSITION: absolute; TOP: 112px" runat="server" Text="RandomPassword"></asp:Button> <asp:Label id="lblNewPassword" style="Z-INDEX: 104; LEFT: 392px; POSITION: absolute; TOP: 152px" runat="server" Width="160px"></asp:Label> <asp:TextBox id="TextBoxPasswordLength" style="Z-INDEX: 101; LEFT: 336px; POSITION: absolute; TOP: 112px" runat="server" Width="28px"></asp:TextBox> <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 216px; POSITION: absolute; TOP: 112px" runat="server" Width="91px">Password Length</asp:Label> </form> </body> </HTML>
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents RndPassword As System.Web.UI.WebControls.Button
Protected WithEvents TextBoxPasswordLength As System.Web.UI.WebControls.TextBox
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents lblNewPassword As System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub RndPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RndPassword.Click
'These constant are the minimum and maximum length for random
'length passwords. Adjust these values to your needs.
Const minLength = 6
Const maxLength = 20
Dim myLength
Try
myLength = Convert.ToInt32(TextBoxPasswordLength.Text())
Catch ex As Exception
myLength = 0
End Try
Dim X, Y, strPW
If myLength = 0 Then
Randomize()
myLength = Int((maxLength * Rnd()) + minLength)
End If
For X = 1 To myLength
'Randomize the type of this character
Y = Int((3 * Rnd()) + 1) '(1) Numeric, (2) Uppercase, (3) Lowercase
Select Case Y
Case 1
'Numeric character
Randomize()
strPW = strPW & Chr(Int((9 * Rnd()) + 48))
Case 2
'Uppercase character
Randomize()
strPW = strPW & Chr(Int((25 * Rnd()) + 65))
Case 3
'Lowercase character
Randomize()
strPW = strPW & Chr(Int((25 * Rnd()) + 97))
End Select
Next
lblNewPassword.Text() = strPW
End Sub
End Class
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Warning: Unknown(): Unable to call () - function does not exist in Unknown on line 0 (PHP)
- how to call a function in href? (ASP.NET)
- call a function (C)
- how to call this function...using menu..! (C++)
- Using a for loop to sum an integer n and call function add_it (C)
Other Threads in the ASP.NET Forum
- Previous Thread: Listbox Items as an array
- Next Thread: how to loop thru checked checkbox to retrieve its value?!?


Linear Mode