how to generate random password?

Posted by Bageshkumarbagi under C# on 10/16/2012 | Points: 10 | Views : 4058 | Status : [Member] | Replies : 4
hi,
i want to generate one time password .how can i generate random password.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Vasanthmvp on: 10/16/2012 [Member] Starter | Points: 25

Up
0
Down
Hi, its always good to allow a randomly generated password.
Here, by taking a string allowchars = "all the alphabets(small,capital),numbers".

MethodName()

{
string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
// By using the Random function we get a random num.
Random randNum = new Random();
//Now, till the password length, we loop through the string array characters each character is generated. [index values of the string array is taken as the random num genearated] and take these characters in to a character array.
char[] chars = new char[PasswordLength];
int allowcharsCount = allowchars .Length;
for (int i = 0; i < PasswordLength; i++)
{
chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
}

return new string(chars);
}


To see more examples, visit:
http://www.dotnetspider.com/resources/23545-How-generate-random-password.aspx
To set a more robust password: http://www.4guysfromrolla.com/articles/101205-1.aspx

Regards,

Awesome Coding !! :)

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 10/17/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down

public string GetRandomNumbers(int numChars_Length)
{
string[] chars = { "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","A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "S",
"T", "U", "V", "W", "X", "Y", "Z", "0", "@", "#", "$", "!" };

Random rnd = new Random();
string random = string.Empty;
for (int i = 0; i < numChars_Length; i++)
{
random += chars[rnd.Next(0, 66)];
}
return random;
}


Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 10/17/2012 [Member] Bronze | Points: 25

Up
0
Down
http://www.c-sharpcorner.com/UploadFile/rohatash/generate-random-password-in-Asp-Net/

from the above link you can generate a random password

Thanks
Pavan Kumar
Mark Answer if this fits the need

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 10/17/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi... @Bageshkumarbagi
Please Mark As Answer if post helps you.

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response