Beispiel #1
0
        public static User SignIn(string username, string password)
        {
            var user = Configs.userCollection.Find(new BsonDocument()
            {
                { "Username", username }
            }).FirstOrDefault();

            if (user != null)
            {
                User foundUser = BsonSerializer.Deserialize <User>(user);
                if (/* Utility.CheckHashMatch( password, foundUser.Password )*/ SuperUtilityClass.CheckHashMatch(password, foundUser.Password))
                {
                    foundUser.IsLoggedIn = true;
                    UserController.UpdateUserInfo(foundUser);
                    Console.WriteLine("User Signing In Successful");
                    return(foundUser);
                }
                else
                {
                    Console.WriteLine("Wrong Username or password");
                }
            }

            return(null);
        }
Beispiel #2
0
        public static User SignUp(string username, string password)
        {
            var foundUser = Configs.userCollection.Find(new BsonDocument()
            {
                { "Username", username }
            }).FirstOrDefault();

            if (foundUser != null)
            {
                throw (new UserAuthenticationException("User Already Exists"));
            }
            else
            {
                User         user     = new User(username, /*Utility.GetHash256String(password)*/ SuperUtilityClass.GetHash256String(password));
                BsonDocument bsonUser = user.ToBsonDocument();
                Configs.userCollection.InsertOne(bsonUser);
                return(user);
            }
        }