private LoginResult Register(Models.Api.Login data) { var user = database.Users.FirstOrDefault(u => u.Login == data.Username); if (user == null) { var newUser = new Models.User() { Login = data.Username, PasswordHash = BCrypt.Generate(Encoding.Unicode.GetBytes(data.Password), salt, 8) }; database.Users.Add(newUser); database.SaveChanges(); Authenticate(newUser).Wait(); return(new LoginResult() { Result = "accept", Message = "Регистрация завершена успешно" }); } else { return(new LoginResult() { Result = "reject", Message = "Ошибка в запросе" }); } }
private LoginResult Register(Models.Api.Login data) { var user = database.Users.FirstOrDefault(u => u.Login == data.Username); var passwordHash = Utils.PasswordHasher.Default.Hash(data.Password); if (user == null) { var newUser = new Models.User() { Login = data.Username, PasswordHash = passwordHash }; database.Users.Add(newUser); database.SaveChanges(); Task.Run(async() => await Authenticate(newUser)); return(new LoginResult() { Result = "accept", Message = "Регистрация завершена успешно" }); } else { return(new LoginResult() { Result = "reject", Message = "Ошибка в запросе" }); } }