Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Password Generator
Author:
Michel Renaud
E-mail:
Click to e-mail author
Submitted:
8/25/2007
Version:
VB 2005
Compatibility:
VB 2005, VB 2008
Category:
String Manipulation
Views:
30356
Function that generates random passwords.
Declarations:
'none
Code:
Dim rNum As New Random(100) Dim rLowerCase As New Random(500) Dim rUpperCase As New Random(50) Dim psw As String Dim RandomSelect As New Random(50) Public Function Gen_Psw(ByVal Lenght As Integer, Optional ByVal Reset As Boolean = False) As String Dim i As Integer Dim CNT(2) As Integer Dim Char_Sel(2) As String Dim iSel As Integer 'clear old passwords If Reset = True Then psw = "" End If For i = 1 To Lenght 'create random numbers that will represent 'each : upercase,lowercase,numbers CNT(0) = rNum.Next(48, 57) 'Numbers 1 to 9 CNT(1) = rLowerCase.Next(65, 90) ' Lowercase Characters CNT(2) = rUpperCase.Next(97, 122) ' Uppercase Characters 'put characters in strings Char_Sel(0) = System.Convert.ToChar(CNT(0)).ToString Char_Sel(1) = System.Convert.ToChar(CNT(1)).ToString Char_Sel(2) = System.Convert.ToChar(CNT(2)).ToString 'pick one of the three above for a character At Random iSel = RandomSelect.Next(0, 3) 'colect all characters generated through the loop psw &= Char_Sel(iSel) ' reset with new password If Reset = True Then psw.Replace(psw, Char_Sel(iSel)) End If Next Return psw End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement