public void Test_ProfileEncryptRoundTrip() { var password = "******"; KanpachiProfile profile = new KanpachiProfile("myprofile", "SOME400", "MYUSER"); profile.PasswordDecrypted = password; profile.Password = SecUtils.EncryptProfile(profile); profile.PasswordDecrypted = SecUtils.DecryptProfile(profile); Assert.True(password == profile.PasswordDecrypted); }
public void Test_AesRoundTrip() { var passphrase = "!!!PaSs_pHr@s3_"; var secret = "hello world"; string encrypted = Convert.ToBase64String(SecUtils.EncryptAes(passphrase, secret)); string decrypted = SecUtils.DecryptAes(passphrase, encrypted); Assert.True(secret == decrypted); // another round to be safe encrypted = Convert.ToBase64String(SecUtils.EncryptAes(passphrase, decrypted)); decrypted = SecUtils.DecryptAes(passphrase, encrypted); Assert.True(secret == decrypted); }
// UF private void Process() { { try { Count++; int LogStatus = UsersBO.ValidateUser(txtUserName.Text, SecUtils.GetPassword(txtPassword.Text)); if (LogStatus == -1) { SecUtils.InsertLogFail(txtUserName.Text); if (SecUtils.CheckCountLogFail(this, txtUserName.Text) == false) { btnExit_Click(null, null); } MessageBox.Show("Sai Username hoặc Password !", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPassword.Focus(); return; } else if (LogStatus == 0) { MessageBox.Show("User đang bị khóa !", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { if (SecUtils.CheckCountLogFail(this, txtUserName.Text) == false) { btnExit_Click(null, null); } if (Global.LockUserID == 0) { UsersModel mU = (UsersModel)UsersBO.Instance.FindByAttribute("LoginName", txtUserName.Text)[0]; Global.UserID = mU.ID; Global.UserGroupID = mU.UserGroupID; Global.UserName = txtUserName.Text.Trim(); Global.IsFullView = mU.IsFullView; Global.FullName = mU.FirstName + " " + mU.MiddleName + " " + mU.LastName; Global.ShiftID = 0; Global.CashierNo = ""; status = true; LoginStatus = true; // Gán thông tin lúc đăng nhập Global.LockUserID = 0; Global.LockUserName = ""; Global.DoTime = DateTime.Now; Global.IsCheckLock = true; this.Close(); } else { UsersModel mU = (UsersModel)UsersBO.Instance.FindByAttribute("LoginName", txtUserName.Text)[0]; if (mU.ID == Global.LockUserID) { Global.UserID = mU.ID; Global.UserGroupID = mU.UserGroupID; Global.UserName = txtUserName.Text.Trim(); Global.IsFullView = mU.IsFullView; Global.FullName = mU.FirstName + " " + mU.MiddleName + " " + mU.LastName; Global.ShiftID = 0; Global.CashierNo = ""; status = true; LoginStatus = true; Global.LockUserID = 0; Global.LockUserName = ""; // Gán thông tin lúc đăng nhập Global.LockUserID = 0; Global.LockUserName = ""; Global.DoTime = DateTime.Now; Global.IsCheckLock = true; this.Close(); } else { MessageBox.Show(string.Format("Chương trình đang được sử dụng bởi [{0}] !", Global.LockUserName), "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }