User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Troubleshooting Call Function

  #1  
Jan 24th, 2006
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Call Function

  #2  
Jan 24th, 2006
are you trying to put it on the aspx page or in the codebehind?
Reply With Quote  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Call Function

  #3  
Jan 24th, 2006
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.

I have created a random password generator function in asp.net (vb.net)
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.
Reply With Quote  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: Call Function

  #4  
Jan 24th, 2006
codes behind page.
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Call Function

  #5  
Jan 25th, 2006
here ya go hope this helps

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>
WebForm1.aspx
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 9:19 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC