Generating random passwords

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Generating random passwords

    Hello all:

    I am trying to build a standar Web registration screen and was wondering of
    what algo to use to generate a random password for users.

    Any kind of help would be greatly appreciated.

    Thanks.


    Zhwgnon Flrq Guest

  2. Similar Questions and Discussions

    1. Using Math.random to go to random frames
      Hello everyone. My cerebral density is preventing me from seeing the solution to this problem. I have the following code which causes the user to...
    2. Generating random numbers?
      Can someone remind me of the name for the class/method for generating random numbers? I did a quick grep through the library and a google, but all...
    3. Random image in a random place.
      Anyone know javascript? I have a grid(4 x 4) of 16 spacer images and a few text links on the side. Each text link represents a different folder of...
    4. Why are passwords in /etc?
      This may be a silly question: Why is /etc/shadow in /etc? Generally, applications and static data go in /usr. You could mount /usr read-only...
    5. generating random numbers
      How do I generate a random number between 1 and 10? I need to capture information of potential clients and randomly assign them to salespersons....
  3. #2

    Default Generating random passwords

    >-----Original Message-----
    >Hello all:
    >
    >I am trying to build a standar Web registration screen
    and was wondering of
    >what algo to use to generate a random password for users.
    >
    >Any kind of help would be greatly appreciated.
    >
    >Thanks.
    >
    >
    >.
    This article shows how to generate a random alpha-numeric
    password for an online user-registration. Calling the
    function GeneratePassword() will return a alpha-numeric
    string of 10 digits (in this example) which can be sent as
    a system generated password to the user and the relevant
    record in the database. To generate a particular digit
    password, change the 10 in GeneratePassword() function to
    your choice.
    private string GetPassword(int nLength)
    {
    int i;
    double nRnd;
    Random oRandom;
    string c="";
    int a, b, d;
    bool bMadeConsonant = false;
    const string strAllConsonants="bcdfghjklmnpqrstvwxyz";
    const string strVocal = "aeiou";
    const string intnum="0123456789";
    string sPassword = "";
    for(i=0;i < nLength;i++)
    {
    oRandom = new Random();
    nRnd = oRandom.NextDouble();
    if(sPassword != "" && !bMadeConsonant && (nRnd < 0.30))
    {
    a = Convert.ToInt16(intnum.Length *
    oRandom.NextDouble()) + 1;
    c = intnum.Substring(a,1);
    c = c + c;
    i = i + 1;
    bMadeConsonant = true;
    }
    else
    {
    if(!bMadeConsonant && (nRnd< 0.60))
    {
    try
    {
    b = Convert.ToInt16(strAllConsonants.Length *
    oRandom.NextDouble()) + 1;
    c = strAllConsonants.Substring(a, 1);
    bMadeConsonant = true;
    }
    catch(ArgumentOutOfRangeException)
    {}
    }
    else
    {
    try
    {
    d = Convert.ToInt16(strVocal.Length *
    oRandom.NextDouble()) + 1;
    c = strVocal.Substring(d, 1);
    bMadeConsonant = false;
    }
    catch(ArgumentOutOfRangeException)
    {}
    }
    }
    sPassword += c;
    }
    if(sPassword.Length > nLength)
    sPassword = sPassword.Substring(0,nLength);
    return sPassword;
    }

    public string GeneratePassword()
    {
    string sPasswd=GetPassword(10);
    while(sPasswd=="")
    sPasswd=GetPassword(10);
    return sPasswd;
    }


    >
    amit agarwal Guest

  4. #3

    Default Re: Generating random passwords

    Amit:

    The code you sent did not compile. Anyways, I wrote a similar function (a
    lot simplified though) to generate a random password of length 8.

    // This function generates a random alphanumeric password of length 8.
    private string GenerateRandomPassword ()
    {
    const string alphabets = "abcdefghijklmnopqrstuvwxyz";
    const string digits ="0123456789";
    StringBuilder password = new StringBuilder (8);
    Random rng = new Random ();
    int n = 0;

    for (int i = 0; i < 8; ++i)
    {
    if (i % 2 == 0)
    {
    n = rng.Next (26);
    password.Append (alphabets [n]);
    }
    else
    {
    n = rng.Next (10);
    password.Append (digits [n]);
    }
    }

    return password.ToString ();
    }

    Thanks.

    "amit agarwal" <amit_agarwal@idealake.com> wrote in message
    news:068101c3ce9e$b9aaa9b0$a401280a@phx.gbl...
    >
    > >-----Original Message-----
    > >Hello all:
    > >
    > >I am trying to build a standar Web registration screen
    > and was wondering of
    > >what algo to use to generate a random password for users.
    > >
    > >Any kind of help would be greatly appreciated.
    > >
    > >Thanks.
    > >
    > >
    > >.
    >
    > This article shows how to generate a random alpha-numeric
    > password for an online user-registration. Calling the
    > function GeneratePassword() will return a alpha-numeric
    > string of 10 digits (in this example) which can be sent as
    > a system generated password to the user and the relevant
    > record in the database. To generate a particular digit
    > password, change the 10 in GeneratePassword() function to
    > your choice.
    > private string GetPassword(int nLength)
    > {
    > int i;
    > double nRnd;
    > Random oRandom;
    > string c="";
    > int a, b, d;
    > bool bMadeConsonant = false;
    > const string strAllConsonants="bcdfghjklmnpqrstvwxyz";
    > const string strVocal = "aeiou";
    > const string intnum="0123456789";
    > string sPassword = "";
    > for(i=0;i < nLength;i++)
    > {
    > oRandom = new Random();
    > nRnd = oRandom.NextDouble();
    > if(sPassword != "" && !bMadeConsonant && (nRnd < 0.30))
    > {
    > a = Convert.ToInt16(intnum.Length *
    > oRandom.NextDouble()) + 1;
    > c = intnum.Substring(a,1);
    > c = c + c;
    > i = i + 1;
    > bMadeConsonant = true;
    > }
    > else
    > {
    > if(!bMadeConsonant && (nRnd< 0.60))
    > {
    > try
    > {
    > b = Convert.ToInt16(strAllConsonants.Length *
    > oRandom.NextDouble()) + 1;
    > c = strAllConsonants.Substring(a, 1);
    > bMadeConsonant = true;
    > }
    > catch(ArgumentOutOfRangeException)
    > {}
    > }
    > else
    > {
    > try
    > {
    > d = Convert.ToInt16(strVocal.Length *
    > oRandom.NextDouble()) + 1;
    > c = strVocal.Substring(d, 1);
    > bMadeConsonant = false;
    > }
    > catch(ArgumentOutOfRangeException)
    > {}
    > }
    > }
    > sPassword += c;
    > }
    > if(sPassword.Length > nLength)
    > sPassword = sPassword.Substring(0,nLength);
    > return sPassword;
    > }
    >
    > public string GeneratePassword()
    > {
    > string sPasswd=GetPassword(10);
    > while(sPasswd=="")
    > sPasswd=GetPassword(10);
    > return sPasswd;
    > }
    >
    >
    >
    > >

    Zhwgnon Flrq Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139