public void Register() { var shAccount = new SHAccount(); shAccount.AccountNumber = Guid.NewGuid().ToString(); Console.WriteLine("Please enter your username: "******"Please enter your password: "******"Please enter your first name: "); shAccount.FirstName = Console.ReadLine(); Console.WriteLine("Please enter your last name:"); shAccount.LastName = Console.ReadLine(); Console.WriteLine("Please enter your email: "); shAccount.Email = Console.ReadLine(); // validate user data. var salt = SaltHelper.GenerateSalt(); var encryptPassword = SaltHelper.EncrypString(password, salt); shAccount.Status = SHAccountStatus.ACTIVE; shAccount.PasswordHash = encryptPassword; shAccount.Salt = salt; if (_model.Save(shAccount)) { Console.WriteLine("Create account success!"); } else { Console.WriteLine("Can't create account! Please try again!"); } }
public SHAccount GetByUsername(string username) { SHAccount result = null; var cnn = ConnectionHelper.GetConnection(); cnn.Open(); var cmd = new MySqlCommand( $"SELECT * FROM shaccount where username = '******'", cnn); var reader = cmd.ExecuteReader(); if (reader.Read()) { result = new SHAccount() { AccountNumber = reader.GetString("AccountNumber"), IdentityNumber = reader.GetInt32("IdentityNumber"), Balance = reader.GetInt32("Balance"), UserName = reader.GetString("Username"), PasswordHash = reader.GetString("PasswordHash"), FirstName = reader.GetString("FirstName"), LastName = reader.GetString("LastName"), Phone = reader.GetInt32("Phone"), Address = reader.GetString("Address"), Email = reader.GetString("Email"), Salt = reader.GetString("Salt"), CreatedAt = reader.GetDateTime("CreatedAt"), UpdateAt = reader.GetDateTime("UpdateAt"), Status = (SHAccountStatus)reader.GetInt32("Status") }; } cnn.Close(); return(result); }
public void GenerateUserMenu() { try { while (true) { Console.WriteLine("---------Account Manage----------"); Console.WriteLine("| 1.Edit account |"); Console.WriteLine("| 2.Deposit |"); Console.WriteLine("| 3.Withdraw |"); Console.WriteLine("| 4.Transfer |"); Console.WriteLine("| 5.Log out |"); Console.WriteLine("| 6.Exist |"); Console.WriteLine("---------------------------------"); Console.Write("Enter"); Console.Write("ENTER CHOICE (1-6) = "); var choice = int.Parse(s: Console.ReadLine()); switch (choice) { case 1: _accountController.EditAccount(); break; case 2: _accountController.Deposit(); break; case 3: _accountController.Withdraw(); break; case 4: _accountController.Transfer(); break; case 5: CurrentUser = _accountController.Login(); if (CurrentUser == null) { Console.WriteLine("Login fails! Please try again!"); } break; case 6: Console.WriteLine(value: "GoodBye!!"); Environment.Exit(exitCode: 3); break; } } } catch (Exception e) { Console.WriteLine(value: e); throw; } }
public void GenerateMainMenu() { try { while (CurrentUser == null) { Console.WriteLine("------ SPRING HERO BANK ------"); Console.WriteLine("| 1.Register Account "); Console.WriteLine("| 2.Login "); Console.WriteLine("| 3.Exit "); Console.WriteLine("|---------------------------- "); Console.Write("ENTER CHOICE (1-3) = "); var choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: _accountController.Register(); break; case 2: CurrentUser = _accountController.Login(); if (CurrentUser == null) { Console.WriteLine("Login fails! Please try again!"); } break; case 3: Console.WriteLine("GoodBye!!"); Environment.Exit(3); break; } } switch (CurrentUser.Role) { case 0: GenerateUserMenu(); break; case 1: GenerateAdminMenu(); break; } } catch (Exception e) { Console.WriteLine("Application error, please try again!"); throw; } }
public bool Save(SHAccount shAccount) { try { var cnn = ConnectionHelper.GetConnection(); cnn.Open(); var stringBuilder = new StringBuilder(); stringBuilder.Append("INSERT INTO shaccount "); stringBuilder.Append("(accountNumber, Role, identityNumber, balance, username, PasswordHash, phone, address, createdAt, updateAt, FirstName, LastName, email, salt, status) "); stringBuilder.Append("VALUES "); stringBuilder.Append($"('{shAccount.AccountNumber}', {shAccount.Role},'{shAccount.IdentityNumber}',{shAccount.Balance},'{shAccount.UserName}', '{shAccount.PasswordHash}','{shAccount.Phone}','{shAccount.Address}','{shAccount.CreatedAt.ToString("yyyy-MM-dd")}','{shAccount.UpdateAt.ToString("yyyy-MM-dd")}', '{shAccount.FirstName}', '{shAccount.LastName}', '{shAccount.Email}', '{shAccount.Salt}', {(int) shAccount.Status}),"); stringBuilder.Remove(stringBuilder.Length - 1, 1); var cmd = new MySqlCommand(stringBuilder.ToString(), cnn); cmd.ExecuteNonQuery(); cnn.Close(); return(true); } catch (Exception e) { Console.WriteLine(e); } return(false); }
public void GenerateAdminMenu() { try { while (true) { Console.WriteLine("--------------------------Account Manage---------------------"); Console.WriteLine("| 1.List of users. |"); Console.WriteLine("| 2. List of transaction history. |"); Console.WriteLine("| 3. Search users by name. |"); Console.WriteLine("| 4. Search users by account number. |"); Console.WriteLine("| 5. Search users by phone number. |"); Console.WriteLine("| 6. Add new users. |"); Console.WriteLine("| 7. Block user accounts. |"); Console.WriteLine("| 8. Search transaction history by account number. |"); Console.WriteLine("| 9. Change account information. |"); Console.WriteLine("| 10.Exist |"); Console.WriteLine("-------------------------------------------------------------"); Console.Write("Enter"); Console.Write("ENTER CHOICE (1-10) = "); var choice = int.Parse(s: Console.ReadLine()); switch (choice) { case 1: _accountController.EditAccount(); break; case 2: _accountController.Deposit(); break; case 3: _accountController.Withdraw(); break; case 4: _accountController.Transfer(); break; case 5: CurrentUser = _accountController.Login(); if (CurrentUser == null) { Console.WriteLine("Login fails! Please try again!"); } break; case 6: Console.WriteLine(value: "GoodBye!!"); Environment.Exit(exitCode: 3); break; } } } catch (Exception e) { Console.WriteLine(value: e); throw; } }