示例#1
0
 public static bool register(string userName, string password)
 {
     if (hashTable.Contains(userName))
     {
         Console.WriteLine("User exist");
         log.Error("Attempt to register a user that exist");
         return(false);
     }
     else
     {
         if (!IsValid.isValidUser(userName, password))
         {
             return(false);
         }
         hashTable.Add(userName, password);
         Console.WriteLine("created a new user name: " + userName);
         log.Info("created a new user name: " + userName);
         User u = new User(userName, password, Board.CreateBoard(userName));
         users.Add(u);
         datUsers.Add((new DatUser(u.userName, u.password, u.userName)));
         return(UserHandler.saveUsers(datUsers));
     }
 }
示例#2
0
        public static bool login(string userName, string password)
        {
            if (users == null)
            {
                datUserToUser(UserHandler.getUsers());
            }
            if (hashTable == null || !hashTable.Contains(userName))
            {
                Console.WriteLine("User not exist: " + userName);
                log.Error("Attempt to sign in with user that not exist");
                return(false);
            }
            else
            {
                if ((string)hashTable[userName] != password)
                {
                    Console.WriteLine("Incorrect password");
                    log.Warn(userName + " tried to login with incorrect password");
                    return(false);
                }
                else
                {
                    User u = getUserByEmail(userName);
                    if (u.logedIn)
                    {
                        log.Error("user is already loged in: " + userName);
                        return(false);
                    }
                    u.initiateLogin();
                    Console.WriteLine(userName + " loged in succesfuly");
                    log.Info(userName + " loged in");

                    return(true);
                }
            }
        }