Jan 29, 2009
Jan 17, 2009
Automatic Random Password Generator in C#
Use cryptography namespace to calculate random passwords. Generate password with varied lenght as of your requirments call function generate(int)
public string RandomPassword(int lnth)
{
if (lnth <>
{
lnth = 5;
}
Random random = new Random();
string password = md5gen(random.Next().ToString()).Substring(0 , 16);
string newPass = "";
random = new Random();
for (int i = 0; i <>
{
if (random.Next(0 , 2) == 1)
newPass += password.Substring(i , 1).ToUpper();
else
newPass += password.Substring(i , 1);
}
return newPass;
}
private string md5gen(string str)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bt= md5.ComputeHash(Encoding.ASCII.GetBytes(str));
StringBuilder stringBuilder = new StringBuilder();
foreach (byte byt in bt)
{
stringBuilder.AppendFormat("{0:x2}" , byt);
}
return stringBuilder.ToString();
}
Use cryptography namespace to calculate random passwords. Generate password with varied lenght as of your requirments call function generate(int)
public string RandomPassword(int lnth)
{
if (lnth <>
{
lnth = 5;
}
Random random = new Random();
string password = md5gen(random.Next().ToString()).Substring(0 , 16);
string newPass = "";
random = new Random();
for (int i = 0; i <>
{
if (random.Next(0 , 2) == 1)
newPass += password.Substring(i , 1).ToUpper();
else
newPass += password.Substring(i , 1);
}
return newPass;
}
private string md5gen(string str)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bt= md5.ComputeHash(Encoding.ASCII.GetBytes(str));
StringBuilder stringBuilder = new StringBuilder();
foreach (byte byt in bt)
{
stringBuilder.AppendFormat("{0:x2}" , byt);
}
return stringBuilder.ToString();
}
Jan 13, 2009
Genetic Programming C#: How to provide file drag-and-drop functionality in a Visual C# application
Subscribe to:
Posts (Atom)