public User Login(LoginModel model) { var userSalt = DB.Users.Where(u => u.email == model.email).Select(u => u.passwordSalt).SingleOrDefault(); if (userSalt == null) { return(null); } string saltedPass = PasswordHashingUtility.GenerateSaltedHash(model.password, userSalt); return(DB.Users.Include(x => x.receivedNotification).Include(x => x.team).Where(x => x.email.Equals(model.email, StringComparison.OrdinalIgnoreCase) && x.password == saltedPass).FirstOrDefault()); }
//Inserts user if the user's email is not in use. public User Register(User user) { //Random salt is created var salt = PasswordHashingUtility.GenerateSalt(); //Hash is created by using random salt and password user.password = PasswordHashingUtility.GenerateSaltedHash(user.password, salt); user.passwordSalt = salt; if (DB.Users.Any(x => x.email == user.email)) { return(null); } DB.Users.Add(user); DB.SaveChanges(); return(user); }