[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

ASP.NET VB Generate Alpha Numeric Password

I need help on ASP.NET VB to generate an Alpha Numeric Password (6 char).
0
dynamicrevolutions
Asked:
dynamicrevolutions
  • 2
2 Solutions
 
nurbekCommented:
   Public Function GeneratePass(ByVal LenPass)
        Dim gnrnum
        Dim ss
        Randomize()
        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)
        Loop
        GeneratePass= gnrnum
    End Function


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

0
 
Ryan ChongCommented:
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"
    Randomize
   
    output = ""
    Do While Len(output) < digits
        s = Int(Rnd * Len(keyStr)) + 1
        output = output & Mid$(keyStr, s, 1)
    Loop
   
    GetRandomKey = output
End Function

myPassword = GetRandomKey(6)
0
 
Ryan ChongCommented:
hmm.. sorry, forget that the above may only works in ASP, yet not ASP.NET ...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now