private void btn_Login_Click(object sender, EventArgs e) { var userid = txt_userid.Text.Trim(); if (string.IsNullOrWhiteSpace(userid)) { txt_userid.Focus(); txt_userid.BackColor = Color.Red; return; } var password = txt_password.Text.Trim(); if (string.IsNullOrWhiteSpace(password)) { txt_password.Focus(); txt_password.BackColor = Color.Red; return; } var user = UserCore.GetUser(userid); if (user != null) { var encode = EncodeCore.MD5Encoding(user.UserID, password, user.Salt); if (encode == user.Password) { //验证成功 AppCommon.CurrentUserId = user.UserID; AppCommon.CurrentPassword = password; this.Close(); } } }
private void Set(UserSecret model) { this.txt_userid.Text = model.UserID; var key = EncodeCore.MD5Encoding(model.UserID, model.Salt, AppCommon.CurrentPassword); this.txt_password.Text = EncodeCore.DesDecrypt(model.Password, key); this.Salt = model.Salt; this.txt_type.Text = model.Type; this.txt_remark.Text = model.Remark; }
private UserSecret Get() { var model = new UserSecret() { Id = this.Id, UserID = this.txt_userid.Text.Trim(), Password = this.txt_password.Text.Trim(), Salt = this.Salt, Type = this.txt_type.Text.Trim(), Remark = this.txt_remark.Text.Trim() }; var key = EncodeCore.MD5Encoding(model.UserID, model.Salt, AppCommon.CurrentPassword); model.Password = EncodeCore.DesEncrypt(model.Password, key); return(model); }
private void btn_OK_Click(object sender, EventArgs e) { var userId = txt_userId.Text.Trim(); if (userId.Length < 6) { MessageBox.Show("用户名至少6个字符"); return; } var password = txt_password.Text.Trim(); var password2 = txt_password2.Text.Trim(); if (password != password2) { MessageBox.Show("两次输入的密码不一致,请重新输入"); return; } var regex = new Regex(@" (?=.*[0-9]) #必须包含数字 (?=.*[a-z]) (?=.*[A-Z]) #必须包含小写和大写字母 (?=([\x21-\x7e]+)[^a-zA-Z0-9]) #必须包含特殊符号 .{8,30} #至少8个字符,最多30个字符 ", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); if (!regex.IsMatch(password)) { MessageBox.Show("密码不符合规则,请重新设计密码"); return; } UserCore.CreateUser(); new SecretCore().Create(); var user = new User() { Salt = Guid.NewGuid().ToString().Replace("-", ""), UserID = userId }; user.Password = EncodeCore.MD5Encoding(user.UserID, password, user.Salt); UserCore.Insert(user); this.Close(); }