Posts: 228
Threads: 7
Joined: Sep 2010
Reputation:
5
12-06-2011, 10:09 AM
(This post was last modified: 04-28-2012, 10:06 AM by ★Cooldude★.)
Code: Function GeneratePassword(Byval Length)
If (Length < 5) Then
Length = 5 'Do not allow a password of length less than 5
End If
Dim alphabet As String() = Split("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", ",") 'Declare Our Alphabet
Dim numbers As String() = Split("0,1,2,3,4,5,6,7,8,9", ",") 'Declare our numbers
Dim Symbols As String() = Split("!,£,$,%,^,&,*,(,),{,},~,@,:,;,#,?,/,>,.,<", ",") 'Declare our symbols
Dim Rand As New Random 'Declare our random
Dim Password As String = "" ''Decalre our password as an empty string
While (Password.Length() < length)
If (Password.Length() = (length - 1)) Then
Password += Symbols((Rand.Next(0, UBound(Symbols))))
ElseIf Password.Length() >= (length - 3) Then
Password += numbers(Rand.Next(0, UBound(numbers)))
Else
Password += alphabet(Rand.Next(0, UBound(alphabet)))
End If
End While
Return Password
End Function
After making the PHP version of this password generator (Which can be found here) I decided that I wanted to create a VB.Net version.
Usage:
Example:
Output: xBUFaMJOtoTK45(
Enjoy.
(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Posts: 39
Threads: 18
Joined: Feb 2011
Reputation:
1
Thanks for the share Dude , will take a look a it when i get time.
Posts: 50
Threads: 12
Joined: Nov 2011
Reputation:
1
nice man looks good, I may even use it in my custom password checker control if thats cool with you?
(and i can actually be bothered to update my control) lol, You will get credits of course
Posts: 2,216
Threads: 187
Joined: Jul 2011
Did this get re-posted?
Anyway well done for your first project, nice a cleanly done.
Posts: 228
Threads: 7
Joined: Sep 2010
Reputation:
5
(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Posts: 122
Threads: 14
Joined: Sep 2010
Reputation:
3
12-09-2011, 02:32 AM
(This post was last modified: 12-09-2011, 02:36 AM by milopeach.)
Here is my version, uses random characters and a Select Case to make the password as random as possible.
I made it because most use the string array and it;s easier to use ASCII codes. You can also replace the whole Select Case and IF statements with a
PHP Code: _Password += Chr(Random.Next(33, 126))
Which will give you a bit of everything if you don't want to make it selectable.
Function:
PHP Code: Public Function GeneratePassword(ByVal Length As Integer) Dim Random As New Random Dim NextChar As Integer = Random.Next(0, 6) Dim _Password As String = String.Empty
While True If _Password.Length > Length Then Exit While
If CheckBox1.Checked Then Select Case NextChar Case 0 _Password += Chr(Random.Next(65, 90)) 'Uppercase Letters Case 1 _Password += Chr(Random.Next(97, 122)) 'Lowercase Letters End Select End If If CheckBox2.Checked Then Select Case NextChar Case 5 _Password += Chr(Random.Next(48, 57)) 'Numbers End Select End If If CheckBox3.Checked Then Select Case NextChar Case 2 _Password += Chr(Random.Next(33, 47)) 'Symbols(0) Case 3 _Password += Chr(Random.Next(58, 64)) 'Symbols(1) Case 4 _Password += Chr(Random.Next(91, 96)) 'Symbols(2) End Select End If NextChar = Random.Next(0, 6) End While Return _Password End Function
Usage:
PHP Code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = GeneratePassword(NumericUpDown1.Value) End Sub
Screenshot:
"If you cannot explain something simply, then you do not understand it at all." - Albert Einstein
"The best way to predict the future is to invent it." - Alan Kay
Posts: 113
Threads: 6
Joined: Feb 2012
Reputation:
1
Could i add more symbols and stuff? or will that make the password unusable on some websites...?
Posts: 5,793
Threads: 268
Joined: Sep 2010
Reputation:
85
(02-04-2012, 04:27 PM)Warp 1.9 Wrote: Could i add more symbols and stuff? or will that make the password unusable on some websites...?
I'm pretty sure this is just logical common sense, but it's up to you which symbols you want to use. You'd just be chancing it for which websites would allow certain symbols as password chars that's all. Otherwise, usually websites allow you free will over what kind of complex password you want.
Posts: 113
Threads: 6
Joined: Feb 2012
Reputation:
1
(02-04-2012, 06:22 PM)AceInfinity Wrote: I'm pretty sure this is just logical common sense, but it's up to you which symbols you want to use. You'd just be chancing it for which websites would allow certain symbols as password chars that's all. Otherwise, usually websites allow you free will over what kind of complex password you want. What if i wanted it to spell a certain word in there somewhere but generate random characters around it?
Posts: 5,793
Threads: 268
Joined: Sep 2010
Reputation:
85
(02-04-2012, 07:39 PM)Warp 1.9 Wrote: What if i wanted it to spell a certain word in there somewhere but generate random characters around it?
Again, I would say exactly what i've just said.
Ace Wrote:I'm pretty sure this is just logical common sense, but it's up to you which symbols you want to use. You'd just be chancing it for which websites would allow certain symbols as password chars that's all. Otherwise, usually websites allow you free will over what kind of complex password you want.
That's simply just common sense.
|