private void btnLogin_Click(object sender, EventArgs e) { //Checks: //1. If username or password wrong, give error //Password entry: //1. Password is masked //2. Password does not register space if (cboBoxStatus.Text == "Member") { var chkUser = context.Members.Where(x => x.Username == txtBoxUsername.Text).SingleOrDefault(); if (chkUser != null) { Member m = chkUser; //Check against DB: Username match and Hash(Salt+Password) match if (LoginHashing.CreatePasswordHash(txtBoxPassword.Text, m.Salt) == m.Password) { UserNameFromLogin = txtBoxUsername.Text; UserCategory = (string)cboBoxStatus.SelectedItem; n.GofrmDashboardMember(this, UserNameFromLogin, UserCategory); } else { MessageBox.Show("Username/Password is incorrect!"); } } else { MessageBox.Show("Username/Password is incorrect!"); } } else if (cboBoxStatus.Text == "Librarian") { var chkUser = context.Librarians.Where(x => x.Username == txtBoxUsername.Text).SingleOrDefault(); if (chkUser != null) { Librarian m = chkUser; //Check against DB: Username match and Hash(Salt+Password) match if (LoginHashing.CreatePasswordHash(txtBoxPassword.Text, m.Salt) == m.Password) { UserNameFromLogin = txtBoxUsername.Text; UserCategory = (string)cboBoxStatus.SelectedItem; n.GofrmDashboardLibrarian(this, UserNameFromLogin, UserCategory); } else { MessageBox.Show("Username/Password is incorrect!"); } } else { MessageBox.Show("Username/Password is incorrect!"); } } else { }; }
private void CommitTransaction() { using (TransactionScope ts = new TransactionScope()) { Member m = new Member(); var MemberIDToUse = context.ControlTables.Where(x => x.NumberType == "MemberID").First(); m.MemberID = MemberIDToUse.FirstFreeNo; m.FirstName = firstName; m.LastName = lastName; m.MemberCategory = memberCategory; m.NRIC = NRIC; m.Salutation = salutation; m.Address = address; m.DateOfBirth = dateOfBirth; m.Postcode = postCode; m.Email = email; m.Phone = phoneNumber; m.CurrentNumberOnLoan = currentNumberOnLoan; m.Remarks = remarks; m.Username = UserName; //For password, store the Hashed version //1. Generate salt, and store salt m.Salt = LoginHashing.CreateSalt(50); //2. Hash(salt+password), Store hashed password + salt m.Password = LoginHashing.CreatePasswordHash(Password, m.Salt); //Commit Changes context.Members.Add(m); ControlTable c = MemberIDToUse; c.FirstFreeNo++; context.SaveChanges(); ts.Complete(); } //Show notification, go back LogIn Page //txtUsername.Text = ""; // txtPassword.Text = ""; // txtPasswordCheck.Text = ""; // MessageBox.Show("User created! Next page!"); }