Pages

Wednesday, 16 May 2012

How to generate Random Password


private void RandomPassword()
    {
        string allowedChars = "";

        allowedChars = "1,2,3,4,5,6,7,8,9,0";

        char[] sep = { ',' };
        string[] arr = allowedChars.Split(sep);

        string passwordString = "";

        string temp = "";

        Random rand = new Random();
        for (int i = 0; i < 5; i++)
        {
            temp = arr[rand.Next(0, arr.Length)];
            passwordString += temp;
        }
        strPwd = passwordString;
    }

No comments:

Post a Comment