private void ButtonUpdate_Click(object sender, EventArgs e) { if (!ValidateData()) { MessageBox.Show("You must use numbers in fields except for name."); return; } int result = 0; var db = new AccountDB(); var dbError = db.Open(); if (dbError.Number != 0) { var errorText = $"Cannot connect to database {Environment.NewLine}"; errorText += $"Error Number: {dbError.Number}{Environment.NewLine}"; errorText += $"Error Message: {dbError.Message}"; MessageBox.Show(errorText); } else { if (db.Connected) { var character = FillCharacterData(); // Se hovuer alguma alteração no nome, procura na db. if (name != character.Name) { if (db.ExistCharacter(character.Name)) { MessageBox.Show("Name is already in use."); db.Close(); return; } } result = db.UpdateCharacter(CharacterId, ref character); MessageBox.Show("Character updated."); } else { MessageBox.Show("Database is not connected."); } } db.Close(); if (result > 0) { Close(); } }
private void ButtonUpdate_Click(object sender, EventArgs e) { var username = accounts[selectedAccountIndex].Username; var password = TextNewPassword.Text.Trim(); var email = TextNewEmail.Text.Trim(); var service = TextNewService.Text.Trim(); if (ValidateData(email, ref service)) { var db = new AccountDB(); var dbError = db.Open(); if (dbError.Number != 0) { var errorText = $"Cannot connect to database {Environment.NewLine}"; errorText += $"Error Number: {dbError.Number}{Environment.NewLine}"; errorText += $"Error Message: {dbError.Message}"; MessageBox.Show(errorText); } else { // Se a senha foi modificada, gera uma nova senha. if (password.Length > 0) { password = Hash.GetPassword(username, password); } else { password = accounts[selectedAccountIndex].Password; } if (db.Connected) { db.Update(accounts[selectedAccountIndex].Id, password, Hash.GetHash(username), email, int.Parse(service)); ClearText(); MessageBox.Show("Updated."); } else { MessageBox.Show("Database is not connected."); } } db.Close(); } }
private void TextAccount_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { // Apaga a lista antiga if (accounts != null) { accounts.Clear(); } ComboAccount.Items.Clear(); if (TextAccount.Text.Length > 0) { var db = new AccountDB(); var dbError = db.Open(); if (dbError.Number != 0) { var errorText = $"Cannot connect to database {Environment.NewLine}"; errorText += $"Error Number: {dbError.Number}{Environment.NewLine}"; errorText += $"Error Message: {dbError.Message}"; MessageBox.Show(errorText); } else { if (db.Connected) { accounts = db.GetAccounts(TextAccount.Text.Trim().ToLower()); FillComboAccount(); AccountLabel.Text = $"Account: {accounts.Count} result(s)."; } else { MessageBox.Show("Database is not connected."); } } db.Close(); } } }
private void TextCharacter_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { var name = TextCharacter.Text.Trim(); var db = new AccountDB(); var dbError = db.Open(); if (dbError.Number != 0) { var errorText = $"Cannot connect to database {Environment.NewLine}"; errorText += $"Error Number: {dbError.Number}{Environment.NewLine}"; errorText += $"Error Message: {dbError.Message}"; MessageBox.Show(errorText); } else { if (db.Connected) { var character = db.GetCharacterTempData(name); if (character.Id == 0) { EnableEditControls(false); MessageBox.Show("Character not found."); } else { EnableEditControls(true); } characterId = character.Id; LabelCharacter.Text = $"Character: {character.Character}"; SearchCharacterBox.Text = $"Search for character: Id {character.Id}."; GroupCharacter.Text = $"Character: Selected Character Id: {character.Id}"; } } db.Close(); } }
private void TextAccount_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { var account = TextAccount.Text.Trim().ToLower(); var db = new AccountDB(); var dbError = db.Open(); if (dbError.Number != 0) { var errorText = $"Cannot connect to database {Environment.NewLine}"; errorText += $"Error Number: {dbError.Number}{Environment.NewLine}"; errorText += $"Error Message: {dbError.Message}"; MessageBox.Show(errorText); } else { if (db.Connected) { var accountId = db.GetAccountId(account); if (accountId == 0) { MessageBox.Show("Account not found."); SearchAccountBox.Text = "Search for account: 0 result(s)."; } else { SearchAccountBox.Text = "Search for account: 1 result(s)."; } characters = db.GetCharacterList(accountId); FillCharacterList(); } } db.Close(); } }
private void ButtonCreate_Click(object sender, EventArgs e) { var account = TextAccount.Text.Trim().ToLower(); var password = TextPassword.Text.Trim(); var email = TextEmail.Text.Trim(); var service = TextService.Text.Trim(); if (ValidateData(account, password, email, ref service)) { var db = new AccountDB(); var dbError = db.Open(); if (dbError.Number != 0) { var errorText = $"Cannot connect to database {Environment.NewLine}"; errorText += $"Error Number: {dbError.Number}{Environment.NewLine}"; errorText += $"Error Message: {dbError.Message}"; MessageBox.Show(errorText); } else { if (!db.Exist(account)) { db.Create(account, Hash.GetPassword(account, password), Hash.GetHash(account), email, int.Parse(service)); ClearText(); MessageBox.Show("Account has been created."); } else { MessageBox.Show("Account is already in use."); } } db.Close(); } }
/// <summary> /// Verifica os dados do usuário. /// </summary> /// <param name="version"></param> /// <param name="username"></param> /// <param name="passphrase"></param> /// <param name="result"></param> /// <returns></returns> public AccountData Authenticate(ClientVersion version, string username, string passphrase, out AuthenticationResult result) { if (Configuration.Maintenance) { result = AuthenticationResult.Maintenance; return(null); } if (!Configuration.Version.Compare(version)) { result = AuthenticationResult.VersionOutdated; return(null); } if (username.Length < Constants.MinStringLength || passphrase.Length < Constants.MinStringLength) { result = AuthenticationResult.StringLength; return(null); } var hash = new Hash(); var database = new AccountDB(); var dbError = database.Open(); if (dbError.Number != 0) { Global.WriteLog(LogType.System, $"Failed to authenticate user {username}", LogColor.Red); Global.WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red); Global.WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red); result = AuthenticationResult.Error; return(null); } var account = database.GetAccount(username); if (account.AccountId > 0) { account.Banned = database.IsBanned(account.AccountId); } if (account.AccountId == 0) { result = AuthenticationResult.WrongUserData; return(account); } if (account.Activated == 0) { result = AuthenticationResult.AccountIsNotActivated; return(account); } if (account.Passphrase.CompareTo(hash.Compute(passphrase)) != 0) { result = AuthenticationResult.WrongUserData; return(account); } if (account.Banned) { result = AuthenticationResult.AccountIsBanned; return(account); } database.UpdateLastLoginDate(account.AccountId); database.Close(); result = AuthenticationResult.Success; return(account); }