private bool InitializeDataBase(string dataDirectory, string userName, string password) { bool tmpCreateResult = false; var tmpSQLiteDataBase = new HuiruiSoft.Data.SQLite.GeneralSQLiteDataBase(); tmpSQLiteDataBase.DataSource = string.Format(@"{0}\SafePassData.dat", dataDirectory); tmpSQLiteDataBase.Password = Md5DigestHelper.Md5Salt(password, userName); tmpSQLiteDataBase.CreateDataBase(); var tmpResourceStream = ResourceStreamHelper.GetStream("resources.database.SafePass.sql", typeof(ResourceFinder)); if (tmpResourceStream != null) { byte[] bytes = new byte[tmpResourceStream.Length]; tmpResourceStream.Read(bytes, 0, bytes.Length); string tmpCommandString = System.Text.Encoding.UTF8.GetString(bytes); tmpSQLiteDataBase.ExecuteNonQuery(tmpCommandString); var tmpRootCatalog = new AccountCatalog(); tmpRootCatalog.Depth = 1; tmpRootCatalog.ParentId = -1; tmpRootCatalog.Name = this.textSafePassName.Text; tmpCreateResult = tmpSQLiteDataBase.CreateRootCatalog(tmpRootCatalog); if (tmpCreateResult) { // } } 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); }