public async Task <IActionResult> Create(UserManagementCreate model) { if (ModelState.IsValid) { var user = new User() { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, CreationDate = DateTime.UtcNow, }; var passwordSalt = Guid.NewGuid().ToString(); var userCredential = new UserCredential() { PasswordSalt = passwordSalt, HashedPassword = _cryptography.HashSHA256(model.Password + passwordSalt), }; user.UserCredential = userCredential; _employeeRegistration.Add(user); await _employeeRegistration.SaveChangesAsync(); ViewBag.message = "The User " + model.FirstName + " Is Saved Successfully..!"; return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IActionResult> Create(UserManagementCreate model) { if (ModelState.IsValid) { var passwordSalt = Guid.NewGuid().ToString(); //Random Password Salt is created var user = new Login() { NameUser = model.NameUser, SurnameUser = model.SurnameUser, UserEmail = model.UserEmail, Passwordsalt = passwordSalt, Passwordhash = _cryptography.PassWordHashing(model.Passwordhash + passwordSalt), //Hashes the password before inserting into DB and also assignes passwordSalt UserRole = "User", // User role can be changed by an admin user to "Admin" to give a user admin privilages Id = random_id(), //Creates a random id EmpNum = int.Parse(model.EmpNum), }; _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }