【发布时间】:2018-03-27 20:18:32
【问题描述】:
如何加密注册表单中的密码并将其发送到 mysql,然后我将转到我的登录表单并输入用户名和密码。 给我看一些例子
string input_fname = textBox1.Text;
string input_mname = textBox2.Text;
string input_lname = textBox3.Text;
string input_address = textBox6.Text;
string input_age = textBox5.Text;
string input_password = getMD5(textBox4.Text);
// establishing connection
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
builder.Server = "127.0.0.1";
builder.UserID = "root";
builder.Password = "seven7";
builder.Database = "justsing";
MySqlConnection connection = new MySqlConnection(builder.ToString());
connection.Open();
// sql command
string newuser_sql = "INSERT INTO `justsing`.`karaokeadmin` (`FirstName`, `MiddleName`, `LastName`, `Address`, `Age`, `password`) VALUES (@FirstName,@MiddleName,@LastName,@Address,@Age,@password)";
MySqlCommand newuser = new MySqlCommand(newuser_sql, connection);
newuser.CommandText = newuser_sql;
newuser.Parameters.AddWithValue("@FirstName", input_fname);
newuser.Parameters.AddWithValue("@MiddleName", input_mname);
newuser.Parameters.AddWithValue("@LastName", input_lname);
newuser.Parameters.AddWithValue("@Address", input_address);
newuser.Parameters.AddWithValue("@Age", input_age);
newuser.Parameters.AddWithValue("@password", input_password);
newuser.ExecuteNonQuery();
MessageBox.Show("Inserted Succesfully");
}
public string getMD5(string text)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));
byte[] result = md5.Hash;
StringBuilder str = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
str.Append(result[i].ToString("X2"));
}
return str.ToString();
}
}
如果与用户名和密码匹配,这是验证登录代码
private void button5_Click(object sender, EventArgs e)
{
string lname = textBox7.Text;
string pass = textBox8.Text;
if (lname == "" || pass == "")
{
MessageBox.Show("Empty Fields Detected ! Please fill up all the fields");
}
bool r = validate_login(lname, pass);
if (r)
{
JustSingAdminControlPanel js = new JustSingAdminControlPanel();
js.Show();
}
//code kung ano gustong buksan
else
{
MessageBox.Show("Wrong Input");
}
}
【问题讨论】:
-
向我们展示您的具体尝试以及问题所在。
-
从这里开始,这是开始:codeproject.com/Articles/704865/…
-
我尝试使用 MD5,但后来我在 stackoverflow 的某些部分阅读了 MD5 无法解密...它是单向哈希
-
I tried using MD5 but then I read on some part of the stackoverflow MD5 cannot be decrypted ... it is a one-way hash你做错了。阅读文章。 -
我要展示我的代码