Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
 public abstract AuthResponse changeUser(UserEntry newUser);
Ejemplo n.º 5
0
 public abstract AuthResponse registerUser(UserEntry user);
Ejemplo n.º 6
0
 public AuthResponse(int id, string message, UserEntry user)
 {
     ID       = id;
     Message  = message;
     UserData = user;
 }