private void btnSure_Click(object sender, EventArgs e) { if (CheckField()) //檢查爛位是否無誤 { SIS.DBClass.DBClsLogin Login = new SIS.DBClass.DBClsLogin(); SIS.DBClass.DBClsWinAPEvents WAE = new SIS.DBClass.DBClsWinAPEvents(); string UserID = ""; string OldPwd = ""; string NewPwd = ""; string encryptFormat;//加密格式設定 UserID = My.MyGlobal.GlobalUserID; encryptFormat = "SHA1"; OldPwd = My.MyMethod.HashEncryption(encryptFormat, txtOldPwd.Text); NewPwd = My.MyMethod.HashEncryption(encryptFormat, txtNewPwd.Text); if (Login.UpdatePassword(UserID, OldPwd, NewPwd)) { MessageBox.Show(this, "密碼變更成功!!", "密碼變更"); clearField(); WAE.AddEventData(UserID, "資訊", "密碼變更", "密碼變更成功"); //btn_OK.Click += new System.EventHandler(btn_ClearField_Click); } else { MessageBox.Show(this, "密碼變更失敗!!", "密碼變更"); WAE.AddEventData(UserID, "警告", "密碼變更", "密碼變更失敗"); } } }
//登出 private void TSMI_Logout_Click(object sender, EventArgs e) { foreach (Form childForm in MdiChildren) { childForm.Close(); } SIS.DBClass.DBClsWinAPEvents WAE = new SIS.DBClass.DBClsWinAPEvents(); //將登入結果寫入事件資料庫中 WAE.AddEventData(My.MyGlobal.GlobalUserID, "資訊", "登出", "使用者登出成功"); LoadDefaultValue(); MessageBox.Show(this, "您已經成功登出系統!!", "訊息提示"); }
/// <summary> /// 執行登入動作 /// </summary> /// <returns>登入成功回傳True,否則回傳False</returns> public bool RunLogin() { if (CheckField()) { string UserID; string HashPwd; string encryptFormat;//加密格式設定 string RoleName = ""; encryptFormat = "SHA1"; UserID = txtUserID.Text; HashPwd = My.MyMethod.HashEncryption(encryptFormat, txtPwd.Text); SIS.DBClass.DBClsLogin DbLogin = new SIS.DBClass.DBClsLogin(); SIS.DBClass.DBClsWinAPEvents WAE = new SIS.DBClass.DBClsWinAPEvents(); bool VerifyResult = false; try { VerifyResult = DbLogin.VerifyPWD(UserID, HashPwd); if (VerifyResult == false) { My.ErrorType errType = new My.ErrorType(My.MainErrorType.LoginError); errType.loginError = new My.LoginError(); errType.loginError.AccountOrPasswordError = true; throw new My.MyExceptionHandler(errType); } } catch (My.MyExceptionHandler ex) { MessageBox.Show(ex.Message, "MyExceptionHandler"); return(false); } if (VerifyResult) { //MessageBox.Show("驗證成功"); //將登入結果寫入事件資料庫中 WAE.AddEventData(UserID, "資訊", "登入", "身分驗證成功"); RoleName = DbLogin.RoleIdToRoleName(UserID); My.MyGlobal.GlobalUserID = UserID; My.MyGlobal.GlobalPassword = txtPwd.Text; My.MyGlobal.GlobalHashPassword = HashPwd; My.MyGlobal.GlobalRoleName = RoleName; //執行登錄檔處理 if (RegistryProcess(UserID, RoleName)) { //執行使用者授權動作 if (AuthorityProcess(UserID, RoleName)) { return(true); } else { return(false); } } else { MessageBox.Show("登錄檔作業失敗!!", "Registry作業", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } else { //MessageBox.Show("驗證失敗"); My.MyGlobal.GlobalLoginErrorCounter += 1; if (My.MyGlobal.GlobalLoginErrorCounter >= 3) { MessageBox.Show("[帳號]和[密碼]輸入錯誤超過三次!!,系統將強制關閉", "登入失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning); My.MyGlobal.GlobalSystemShutdown = true; MdiParent.Close(); this.Close(); } //將登入失敗的結果寫入事件資料庫中 WAE.AddEventData(UserID, "警告", "登入", "身分驗證失敗"); MessageBox.Show("[帳號]和[密碼]錯誤!!", "登入失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } else { return(false); } }