Click here to Skip to main content
16,003,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

How to generate random password in asp.net ?


Thanks
Posted

Easiest way? Do what I do:
C#
string randomPassword = Guid.NewGuid().ToString();
 
Share this answer
 
Comments
Simon Bang Terkildsen 22-Aug-11 4:44am    
+5 I Like that one as long as I don't have to enter the password myself :)
OriginalGriff 22-Aug-11 4:52am    
Encourages people to change it to something they will remember! :laugh:
Simon Bang Terkildsen 22-Aug-11 5:35am    
Very true XD
You could use the Membership.GeneratePassword[^] function
 
Share this answer
 
Comments
Simon Bang Terkildsen 22-Aug-11 4:45am    
very nice I didn't know about that one, you got my 5
C#
string passwordChars = "abcde...123..."; // A string containing all the characters that is allowed in the final password
Random random = new Random();
int passwordLength = random.Next(5,7); // the length of the final password

StringBuilder password = new StringBuilder(passwordLength)
for(int i = 0; i < passwordLength; i++)
    // randomly take a character from the passwordChars string and append to the password
    password.Append(passwordChars[random.Next(0, passwordChars.Length)]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900