ASP.NET VB Generate Alpha Numeric Password

Posted on 2004-11-23
Last Modified: 2008-03-17
I need help on ASP.NET VB to generate an Alpha Numeric Password (6 char).
Question by:dynamicrevolutions
    LVL 13

    Accepted Solution

       Public Function GeneratePass(ByVal LenPass)
            Dim gnrnum
            Dim ss
            Do While Len(gnrnum) < LenPass
                ss = 48 + Int(Rnd() * 59)
                If ss <= 57 And ss >= 48 Then gnrnum = gnrnum & Chr(ss)
                If ss <= 90 And ss >= 65 Then gnrnum = gnrnum & Chr(ss)
            GeneratePass= gnrnum
        End Function

    Call it Like
    myPassword = GeneratePass(5) 'where 5 is the length of the password

    LVL 48

    Assisted Solution

    by:Ryan Chong
    or if you want to avoid confusion on "0" and "O", etc, try like below:

    Public Function GetRandomKey(byval digits As Integer) As String
        Dim keyStr As String, output As String, s As Integer
        keyStr = "0123456789abcdefghijklmnpqrstuvwsyzABCDEFGHIJKLMNPQRSTUVWXYZ"
        output = ""
        Do While Len(output) < digits
            s = Int(Rnd * Len(keyStr)) + 1
            output = output & Mid$(keyStr, s, 1)
        GetRandomKey = output
    End Function

    myPassword = GetRandomKey(6)
    LVL 48

    Expert Comment

    by:Ryan Chong
    hmm.. sorry, forget that the above may only works in ASP, yet not ASP.NET ...

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now