Try following code to make password and checking:
// 1) Making Password
using System.Security.Cryptography;
static class CommonMethods
{
public static string MD5Hash(string str)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes( str );
data = md5.ComputeHash(data);
string md5Hash = System.Text.Encoding.ASCII.GetString(data);
return md5Hash;
}
public static bool ConfirmPwd(string pwd)
{
string storedPwd, encryptedPwd;
try
{
StreamReader fsPwdFile =
new StreamReader(
new FileStream(
Program.strPwdFilePath,
FileMode.Open,
FileAccess.Read));
storedPwd = fsPwdFile.ReadToEnd();
fsPwdFile.Close();
}
catch
{ return false;
}
encryptedPwd = MD5Hash(pwd);
if (storedPwd != encryptedPwd)
return false;
return true;
}
}
private void btnOK_Click(object sender, EventArgs e)
{
if (CommonMethods.ConfirmPwd(tbPassword.Text))
{
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
MessageBox.Show
("Wrong password, please re-enter", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
tbPassword.Focus();
return;
}
}
Hope this contains sufficient information, your require.