public static AccountEntity Convert(string encryptKey, AccountModel account) { AccountEntity tmpAccountEntity = null; if (account != null) { tmpAccountEntity = new AccountEntity(); tmpAccountEntity.AccountId = account.AccountId; tmpAccountEntity.AccountGuid = account.AccountGuid; tmpAccountEntity.CatalogId = account.CatalogId; tmpAccountEntity.Name = account.Name; tmpAccountEntity.URL = account.URL; tmpAccountEntity.Order = account.Order; tmpAccountEntity.TopMost = account.TopMost; tmpAccountEntity.Deleted = account.Deleted; tmpAccountEntity.VersionNo = account.VersionNo; tmpAccountEntity.SecretRank = (ushort)account.SecretRank; tmpAccountEntity.Email = EncryptorHelper.DESEncrypt(encryptKey, account.Email); tmpAccountEntity.Mobile = EncryptorHelper.DESEncrypt(encryptKey, account.Mobile); tmpAccountEntity.LoginName = EncryptorHelper.DESEncrypt(encryptKey, account.LoginName); tmpAccountEntity.Password = EncryptorHelper.DESEncrypt(encryptKey, account.Password); tmpAccountEntity.CreateTime = account.CreateTime; tmpAccountEntity.UpdateTime = account.UpdateTime; tmpAccountEntity.Comment = account.Comment; } return(tmpAccountEntity); }
public static AccountAttributeEntity ConvertAttribute(string encryptKey, AccountAttribute attribute) { AccountAttributeEntity tmpAttributeEntity = null; if (attribute != null) { tmpAttributeEntity = new AccountAttributeEntity(); tmpAttributeEntity.AttributeId = attribute.AttributeId; tmpAttributeEntity.Order = attribute.Order; tmpAttributeEntity.Name = attribute.Name; tmpAttributeEntity.AccountId = attribute.AccountId; tmpAttributeEntity.Encrypted = attribute.Encrypted; if (!tmpAttributeEntity.Encrypted) { tmpAttributeEntity.Value = attribute.Value; } else { tmpAttributeEntity.Value = EncryptorHelper.DESEncrypt(encryptKey, attribute.Value); } } return(tmpAttributeEntity); }
private bool CreateApplicationConfig(string configDirectory, string userName, string password) { var tmpSafePassConfig = new SafePassConfiguration(); if (System.Globalization.CultureInfo.CurrentCulture.Name == "zh-CN") { tmpSafePassConfig.Application.LanguageFile = ApplicationDefines.ChineseSimpLanguageFile; } var tmpSecurityProfile = tmpSafePassConfig.Application.Security; tmpSecurityProfile.LockWorkspace = Program.Config.Application.Security.LockWorkspace; tmpSecurityProfile.MasterPassword = Program.Config.Application.Security.MasterPassword; tmpSecurityProfile.CurrentAccount.UserName = userName; tmpSecurityProfile.CurrentAccount.Password = password; tmpSecurityProfile.CurrentAccount.PasswordStored = EncryptorHelper.DESEncrypt(Account.CurrentAccount.SecretKey, tmpSecurityProfile.CurrentAccount.PasswordMd5); tmpSecurityProfile.Clipboard.ClipboardClearOnExit = Program.Config.Application.Security.Clipboard.ClipboardClearOnExit; tmpSecurityProfile.Clipboard.ClipboardClearAfterSeconds = Program.Config.Application.Security.Clipboard.ClipboardClearAfterSeconds; tmpSecurityProfile.SecretRank.SecretRank0Color = Program.Config.Application.Security.SecretRank.SecretRank0Color; tmpSecurityProfile.SecretRank.SecretRank1Color = Program.Config.Application.Security.SecretRank.SecretRank1Color; tmpSecurityProfile.SecretRank.SecretRank2Color = Program.Config.Application.Security.SecretRank.SecretRank2Color; tmpSecurityProfile.SecretRank.SecretRank3Color = Program.Config.Application.Security.SecretRank.SecretRank3Color; tmpSafePassConfig.MainWindow = Program.Config.MainWindow; var tmpCreateResult = ApplicationConfigSerializer.SaveApplicationConfig(Path.Combine(configDirectory, "SafePass.config.xml"), tmpSafePassConfig); return(tmpCreateResult); }
private void buttonOK_Click(object sender, System.EventArgs args) { var tmpInputErrorCaption = SafePassResource.MessageBoxCaptionInputError; var tmpOldPassword = this.textOldPassword.Text.Trim(); var tmpNewPassword = this.textNewPassword.Text.Trim(); if (tmpOldPassword != Account.CurrentAccount.Password) { this.textOldPassword.Focus(); MessageBox.Show(SafePassResource.ChangePasswordWindowPromptPasswordIncorrect, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(tmpNewPassword)) { this.textNewPassword.Focus(); MessageBox.Show(SafePassResource.ChangePasswordWindowPromptPasswordIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (!string.Equals(tmpNewPassword, this.textRepeatPassword.Text)) { this.textRepeatPassword.Focus(); MessageBox.Show(SafePassResource.PasswordRepeatFailed, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.Equals(tmpOldPassword, tmpNewPassword, System.StringComparison.OrdinalIgnoreCase)) { this.textNewPassword.Focus(); MessageBox.Show(SafePassResource.ChangePasswordWindowPromptSameAsOldPassword, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var tmpPasswordMd5 = Md5DigestHelper.Md5Salt(tmpNewPassword, Account.CurrentAccount.UserName); var tmpAccountService = new HuiruiSoft.Safe.Service.AccountService(); var tmpChangeResult = tmpAccountService.ChangePassword(tmpPasswordMd5); if (tmpChangeResult) { DataBaseConfig.Password = tmpPasswordMd5; Account.CurrentAccount.Password = tmpNewPassword; Account.CurrentAccount.PasswordStored = EncryptorHelper.DESEncrypt(Account.CurrentAccount.SecretKey, tmpPasswordMd5); ApplicationConfigSerializer.SaveApplicationConfig(Program.Config); MessageBox.Show(SafePassResource.ChangePasswordWindowMessageChangeSuccess, SafePassResource.Success, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } } catch (System.SystemException exception) { loger.Error(exception); MessageBox.Show(SafePassResource.ChangePasswordWindowMessageChangeFailed, SafePassResource.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected virtual bool CheckValidity() { var tmpUserName = this.textLoginName.Text.Trim(); var tmpPassword = this.textPassword.Text.Trim(); var tmpInputErrorCaption = SafePassResource.MessageBoxCaptionInputError; if (string.IsNullOrEmpty(tmpUserName)) { this.textLoginName.Focus(); MessageBox.Show(SafePassResource.LoginWindowPromptUserNameIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (string.IsNullOrEmpty(tmpPassword)) { this.textPassword.Focus(); MessageBox.Show(SafePassResource.LoginWindowPromptPasswordIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (tmpUserName != Account.CurrentAccount.UserName) { this.textLoginName.Focus(); MessageBox.Show(SafePassResource.LoginWindowPromptUserNameNonExistent, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } var tmpPasswordMd5 = Md5DigestHelper.Md5Salt(tmpPassword, tmpUserName); var tmpPwdEncrypted = EncryptorHelper.DESEncrypt(Account.CurrentAccount.SecretKey, tmpPasswordMd5); if (tmpPwdEncrypted == Account.CurrentAccount.PasswordStored) { Account.CurrentAccount.Password = tmpPassword; DataBaseConfig.Password = tmpPasswordMd5; DataBaseConfig.DataSource = System.IO.Path.Combine(Program.Config.WorkingDirectory, ApplicationDefines.SafePassDbFile); } else { this.textPassword.Focus(); MessageBox.Show(SafePassResource.LoginWindowPromptPasswordIncorrect, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }