![]() |
|
VB.Net | How to make a Random Password Generator - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework) +--- Thread: VB.Net | How to make a Random Password Generator (/Thread-VB-Net-How-to-make-a-Random-Password-Generator) |
VB.Net | How to make a Random Password Generator - Sunlight - 04-27-2013 Introduction In this thread I will teach you how to make a password generator. It is very simple and not hard at all, but some people don't understand how to do it. So that is why I am making this thread. This password generator generates letters and numbers.(you can add symbols if you'd like) Tutorial Time Open up a new Visual Basic project and name it whatever you'd like. For the sake of this tutorial I'll name mine Password Generator. Add the following Textbox1 = name it to txtLength(how long the password will be) Textbox2 = name it to txtResult(where the result will be placed) Button1 = name it to btnGenerate(button that does the commands.) Now, view the code and go right under Form1 and now we are going to declare the following: Code: Dim usechars() As String ' We will use this to put are list of characters in later. For now, it has no value.
Dim rdm As New Random ' We are declaring rdm as a new Random
Dim charlist As String = ("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,1,2,3,4,5,6,7,8,9,0") ' the list of chars that will be used to generate the password. Feel free to add characters.
Dim FinalPW As String = "" ' We are declaring FinalPW as a string, we will later use it for our final password to be stored in.
Dim Number As Integer = 0Code: usechars = Split(charlist, ",") 'Splits the charlist by the comma and adds it to usechars.
FinalPW = "" '
Number = 0
For i As Integer = 1 To txtLength.Text ' the amount of charactors you want in your password will now be known as i.
Number = rdm.Next(0, 61) ' there are 62 chars in the usechars, but since we put 0 as the first number(which is in the list) the we subtract the amount by 1, and the second number should be 61.
FinalPW = FinalPW + usechars(Number) ' Get's a random amount of chars from the list and puts it into FinalPW.
txtResult.Text = FinalPW ' Puts the textbox results as the password stored in FinalPW.
Next |