C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Password Generator in VB.NET


Posted Date: 24 Feb 2008    Resource Type: Code Snippets    Category: Tools

Posted By: Dharmaraj       Member Level: Diamond
Rating:     Points: 7



This code sample is a function which generates Random Password. The length of the password is taken as an argument. The password contains only alphanumeric characters.

To generate random passwords, the function uses Rand() function. With a random integer that the function returns every time it is called, we convert it to a valid ASCII alpha-numeric number and append it to the password we have accumulated so far. This is done as many times as the length of the password.




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




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Password Generator  .  Generate Random Passwords  .  Generate Passwords  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Create New WordDocument using VB.Net.
Previous Resource: Generate New Random Password
Return to Discussion Resource Index
Post New Resource
Category: Tools


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use