Results 1 to 2 of 2

Thread: How to Generate Random Password in vb.net

  1. #1
    Join Date
    Dec 2008
    Posts
    30

    How to Generate Random Password in vb.net

    Hi, I am creating new application in vb.net, but i want that users of the system should not able to generate the passwords it should be generate randomly.
    and i am not able to do this.
    will you please help me out?

  2. #2
    Join Date
    Dec 2008
    Posts
    35

    Re: How to Generate Random Password in vb.net

    The code given below is to generate the random password.
    you can use it according to your requirements

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls

    Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If IsPostBack Then
    Label1.Text = "Please enter a password length (e.g. 8)"
    End If
    End Sub

    Public Shared Function CreateRandomPassword(ByVal PasswordLength As Integer) As String
    Dim _allowedChars As String = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789"
    Dim randNum As New Random()
    Dim chars(PasswordLength - 1) As Char
    Dim allowedCharCount As Integer = _allowedChars.Length

    For i As Integer = 0 To PasswordLength - 1
    chars(i) = _allowedChars.Chars(CInt(Fix((_allowedChars.Length) * randNum.NextDouble())))
    Next i

    Return New String(chars)
    End Function

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    If TextBox1.Text <> "" Then
    Dim myInt As String = TextBox1.Text.ToString()
    Label1.Text = "Your generated password is: " & CreateRandomPassword(Integer.Parse(myInt))
    End If
    End Sub
    End Class

Similar Threads

  1. Replies: 4
    Last Post: 13-01-2012, 05:07 PM
  2. How to use "Math.random()" to generate a random number in JavaScript?
    By Silent~Kid in forum Software Development
    Replies: 5
    Last Post: 03-02-2010, 05:06 AM
  3. Generate random number using VB
    By Bambina in forum Software Development
    Replies: 2
    Last Post: 02-09-2009, 10:56 PM
  4. Generate random data in excel
    By garfield1 in forum Software Development
    Replies: 3
    Last Post: 12-08-2009, 10:40 AM
  5. Generate Random Password In PHP
    By Aaquib in forum Software Development
    Replies: 2
    Last Post: 23-01-2009, 10:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,847,003.24168 seconds with 16 queries