public override void SetFormState(Form form) { form.MaximizeBox = false; form.MinimizeBox = false; form.TopMost = true; form.ShowInTaskbar = true; form.FormClosing += (sender, e) => { if (form.DialogResult == DialogResult.OK) { try { string hashPassword = null; if (SecurtiyService == null) { throw new Exception("安全服务还未初始化"); } if (TextEditPassword.Text.IsNotNullOrEmpty()) { hashPassword = SecurityPublic.ComputeHashString(TextEditPassword.Text); } var userID = SecurtiyService.Login(TextEditUser.Text, hashPassword); SecurityPublic.ApplicationUser = new UserToken() { UserID = userID, }; } catch (Exception err) { UIPublic.ShowExceptionDialog(err); e.Cancel = true; } } }; base.SetFormState(form); }
public string Login(string userID, string password) { T_UserDataTable userTable = new UserDataSet.T_UserDataTable(); var dataService = DataService.Value; dataService.FillBySql(userTable, Sql_QueryUserByName, 0, 1, new DataParameter("@UserName", userID)); if (userTable.Count == 0) { throw new Exception("登录失败"); } if (userTable[0].IsPasswordNull()) { if (password != null) { throw new Exception("登录失败"); } } else if (userTable[0].Password != SecurityPublic.ComputeHashString(password)) { throw new Exception("登录失败"); } return(userTable[0].ID); }