public bool adminEditCustomer(Customer customer) { using (var db = new BankDBContext()) { try { DbCustomer dbcustomer = db.Customers.FirstOrDefault(c => c.NID == customer.nID); if (dbcustomer != null) { dbcustomer.firstName = customer.firstName; dbcustomer.lastName = customer.lastName; string salt = BankCustomerDAL.generateSalt(); string passwordAndSalt = customer.password + salt; byte[] hashedpassword = BankCustomerDAL.generateHash(passwordAndSalt); dbcustomer.password = hashedpassword; dbcustomer.salt = salt; db.SaveChanges(); return(true); } } catch (Exception e) { BankCustomerDAL.errorReport(e.ToString()); return(false); } return(false); } }
public bool adminRegisterCustomer(Customer inCustomer) { try { var newCustomer = new DbCustomer() { firstName = inCustomer.firstName, lastName = inCustomer.lastName, NID = inCustomer.nID }; var db = new BankDBContext(); string salt = BankCustomerDAL.generateSalt(); string passwordAndSalt = inCustomer.password + salt; byte[] hashedpassword = BankCustomerDAL.generateHash(passwordAndSalt); newCustomer.password = hashedpassword; newCustomer.salt = salt; db.Customers.Add(newCustomer); db.SaveChanges(); return(true); } catch (Exception e) { BankCustomerDAL.errorReport(e.ToString()); return(false); } }
public bool isAdminLoginCorrect(Admin admin) { using (var db = new BankDBContext()) { try { DbAdmin adminFound = db.Admins.FirstOrDefault(c => c.ID.Equals(admin.ID)); if (adminFound != null) { byte[] checkPassword = BankCustomerDAL.generateHash(admin.adminPassword + adminFound.adminsalt); bool validAdmin = adminFound.adminpassword.SequenceEqual(checkPassword); return(validAdmin); } return(false); } catch (Exception e) { BankCustomerDAL.errorReport(e.ToString()); return(false); } } }