public override AuthResponse registerUser(UserEntry user) { List <UserEntry> users = readAllUsers(); if (users.Any(usr => usr.Login == user.Login)) { return(new AuthResponse(3, "User already in system")); } if (user.RestrictPassword && !validatePassword(user.Password)) { return(new AuthResponse(4, "Password doesn't match pattern")); } user.Password = new String(Hasher.HashData(user.Password.ToArray())); users.Add(user); writeUsers(users); return(new AuthResponse(0, "Successful registered", user)); }
public override AuthResponse authUser(string login, string password) { UserEntry user = new UserEntry(login, password); List <UserEntry> users = readAllUsers(); UserEntry userData = users.Find(usr => usr.Login == user.Login); if (userData == null) { return(new AuthResponse(2, "User doesn't exists")); } string hash = new String(Hasher.HashData(password.ToArray())); if (userData.Password != hash) { return(new AuthResponse(1, "Wrong password")); } return(new AuthResponse(0, "Successful logged", userData)); }
public override AuthResponse changeUser(UserEntry newUser) { List <UserEntry> users = readAllUsers(); var userData = users.Find(usr => usr.Login == newUser.Login); if (userData == null) { return(new AuthResponse(2, "User doesn't exists")); } if (newUser.RestrictPassword && !validatePassword(newUser.Password)) { return(new AuthResponse(4, "Password doesn't match pattern")); } users.Remove(userData); newUser.Password = new String(Hasher.HashData(newUser.Password.ToArray())); users.Add(newUser); writeUsers(users); return(new AuthResponse(0, "Successfuly changed data", newUser)); }
public abstract AuthResponse changeUser(UserEntry newUser);
public abstract AuthResponse registerUser(UserEntry user);
public AuthResponse(int id, string message, UserEntry user) { ID = id; Message = message; UserData = user; }