public Client Registration(RegisterRequest request) { Client client = _context.Client .FirstOrDefault(c => c.Login.Equals(request.Login)); if (client == null) { string Salt = Pbkdf2Hashing.CreateSalt(); Client newClient = new Client { IdClient = _context.Client.Max(c => c.IdClient) + 1, FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, Phone = request.Phone, Login = request.Login, Password = Pbkdf2Hashing.Create(request.Password, Salt), Salt = Salt, RefreshToken = "tmp" }; _context.Client.Add(newClient); _context.SaveChanges(); return(newClient); } else { throw new LoginOccupiedException("Podany login jest już zajęty, spróbuj inny"); } }
public Client Loggining(LoginRequest request) { Client client = _context.Client .FirstOrDefault(c => c.Login.Equals(request.Login)); if (client != null) { if (Pbkdf2Hashing.Validate(request.Password, client.Salt, client.Password)) { return(client); } else { throw new FalsePasswordException("Podano błędne hasło"); } } else { throw new NoSuchClientException("Klient o podanym loginie nie istnieje"); } }