public static User CreateUser(RegisterDTO registerDTO, HotelRestaurantDBContext dBContext) { User user = new User(); string salt = CreateSalt(); user.UserName = registerDTO.UserName; user.Salt = salt; user.Password = EncryptPassword(registerDTO.Password, salt); dBContext.Users.Add(user); dBContext.SaveChanges(); return(user); }
protected override void Seed(HotelRestaurantDBContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // }
public static User CheckUserLogin(LoginDTO loginDTO, HotelRestaurantDBContext dBContext) { User user = dBContext.Users.Where(u => u.UserName.Equals(loginDTO.UserName)).FirstOrDefault(); if (user == null) { throw new UserNotExistsException(); } if (user.Password.Equals(EncryptPassword(loginDTO.Password, user.Salt))) { return(user); } else { throw new InvalidPasswordException(); } }