Monday, 9 January 2012

Generate Random Password

-----RandomPasswordCrate.cs
public class RandomPasswordCrate
{
public static string GeneratePassword(int PasswordLength)
{
string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789_";
Random randNum = new Random();
char[] chars = new char[PasswordLength];
int allowedCharCount = _allowedChars.Length;
for (int i = 0; i < PasswordLength; i++)
{
chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
}
return new string(chars);
}
}
------In cs Page
protected void Page_Load(object sender, EventArgs e)
{
generatePassword();
}
private void generatePassword()
{
string password = "Your password is: " + RandomPasswordCrate.GeneratePassword(8);
}

2 comments:

  1. really this blog is very helpful for growth of knowledge...Thank You for this information...
    digital image editing

    ReplyDelete
  2. ASP.net this coding for very useful for web and other ...........thnx for sharing such a good post........
    vacation rentals in orlando

    ReplyDelete

Get all non-clustered indexes

DECLARE cIX CURSOR FOR     SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID         FROM Sys.Indexes SI             ...