void BtnGetPassword_Click(object sender, RoutedEventArgs e) { try { var typeItem = ListBoxType.SelectedItem as EncryptionTypeItem; var modeItem = ComboMode.SelectedItem as EncryptionModeItem; if (typeItem == null || modeItem == null) { return; } string strSource = TxtSource.Text; string strID = TxtID.Text; if (string.IsNullOrEmpty(strSource) || string.IsNullOrEmpty(strID)) { ShowErrorMessage(string.Format("Password or ID empty")); return; } strSource = strID + strSource; byte[] temp = ServerHashEncryption.EncryptBytes(Encoding.Unicode.GetBytes(strSource), EncryptionMode.SHA512V00Hex); var aes = ServerAESEncryption.EncryptBytes(temp, EncryptionMode.AES256V02Hex); AppendMessage(string.Format("{0}", ServerEncryptionUtils.Byte2Hex(aes))); } catch (Exception ex) { ShowErrorMessage(ex.Message); } }
/// <summary> /// 用户密码加密 /// </summary> /// <param name="strUserID"></param> /// <param name="strPwdInput"></param> /// <returns></returns> public static string EncryptUserPwd(string strUserID, string strPwdInput) { try { string str = strUserID + strPwdInput; byte[] temp = ServerHashEncryption.EncryptBytes(Encoding.Unicode.GetBytes(str), EncryptionMode.SHA512V00Hex); var aes = ServerAESEncryption.EncryptBytes(temp, EncryptionMode.AES256V02Hex); return(ServerEncryptionUtils.Byte2Hex(aes)); } catch { return(strUserID + strPwdInput); } }
private void Login() { try { if (DatabaseInfo == null) { ShowException(string.Format("Fail.\t DatabaseInfo is null")); return; } string strAccount = TxtAccount.Text.Trim(); string strPassword = TxtPassword.Password.Trim(); if (string.IsNullOrEmpty(strAccount) || string.IsNullOrEmpty(strPassword)) { ShowException(string.Format("Account or password empty!")); return; } SetBusy(true, App.GetLanguageInfo("N008", string.Format("Checking login information, please wait for a moment..."))); bool isFail = true; string strError = string.Empty; OperationReturn optReturn; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, de) => { try { string strAccountEncrypt = App.EncryptStringM002(strAccount); int dbType = DatabaseInfo.TypeID; string strSql; string strConn = DatabaseInfo.GetConnectionString(); string strRentToken = string.Format("00000"); switch (dbType) { case 2: strSql = string.Format("SELECT * FROM T_11_005_{0} WHERE C002 = '{1}'", strRentToken, strAccountEncrypt); optReturn = MssqlOperation.GetDataSet(strConn, strSql); break; case 3: strSql = string.Format("SELECT * FROM T_11_005_{0} WHERE C002 = '{1}'", strRentToken, strAccountEncrypt); optReturn = OracleOperation.GetDataSet(strConn, strSql); break; default: strError = string.Format("Database type not support.\t{0}", dbType); return; } if (!optReturn.Result) { strError = string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message); return; } DataSet objDataSet = optReturn.Data as DataSet; if (objDataSet == null || objDataSet.Tables.Count <= 0) { strError = string.Format("DataSet is null"); return; } if (objDataSet.Tables[0].Rows.Count <= 0) { strError = string.Format("Account not exist.\t{0}", strAccount); return; } DataRow dr = objDataSet.Tables[0].Rows[0]; long userID = Convert.ToInt64(dr["C001"]); string strPass = dr["C004"].ToString(); string strTemp = string.Format("{0}{1}", userID, strPassword); byte[] byteTemp = ServerHashEncryption.EncryptBytes(Encoding.Unicode.GetBytes(strTemp), EncryptionMode.SHA512V00Hex); var aes = ServerAESEncryption.EncryptBytes(byteTemp, EncryptionMode.AES256V02Hex); strTemp = ServerEncryptionUtils.Byte2Hex(aes); if (!strTemp.Equals(strPass)) { strError = string.Format("Password error."); return; } IsLogined = true; UserInfo userInfo = new UserInfo(); userInfo.UserID = userID; userInfo.Account = strAccount; userInfo.Password = strPassword; UserInfo = userInfo; isFail = false; } catch (Exception ex) { strError = string.Format("Fail.\t{0}", ex.Message); } }; worker.RunWorkerCompleted += (s, re) => { worker.Dispose(); SetBusy(false, string.Empty); if (isFail) { ShowException(strError); return; } DialogResult = true; Close(); }; worker.RunWorkerAsync(); } catch (Exception ex) { ShowException(ex.Message); } }