Exemple #1
0
        public ServerResponse Start()
        {
            ServerResponse response = null;

            try
            {
                if (Authorize.PassesGuidelines(newPassword))
                {
                    User user = UserManager.Instance.FindUserByID(userid);

                    byte[]   salt       = Authorize.GenerateSalt();
                    byte[]   saltedHash = Authorize.GenerateSaltedHash(newPassword, salt);
                    Password password   = new Password(saltedHash, salt);

                    bool operationSuccessful = user.ChangePassword(password);

                    if (operationSuccessful)
                    {
                        response = new ServerResponse(userid, Response.Success);
                        UserManager.Instance.SaveUser(user);
                    }
                    else
                    {
                        response = new ServerResponse(userid, Response.InvalidPassword);
                    }
                }
                else
                {
                    response = new ServerResponse(userid, Response.InvalidPassword);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                response = new ServerResponse(userid, Response.ServerError);
            }

            return(response);
        }
Exemple #2
0
        public ServerResponse Create()
        {
            ServerResponse response = null;

            try
            {
                if (Authorize.PassesGuidelines(enteredPassword))
                {
                    byte[]   salt       = Authorize.GenerateSalt();
                    byte[]   saltedHash = Authorize.GenerateSaltedHash(enteredPassword, salt);
                    Password password   = new Password(saltedHash, salt);

                    User newUser = new User(enteredUserName, password);
                    try
                    {
                        UserManager.Instance.SaveUser(newUser);
                        response = new ServerResponse(newUser.id, Response.UserCreated);
                    }
                    catch (MongoWriteConcernException)
                    {
                        response = new ServerResponse(userid, Response.UserAlreadyExists);
                    }
                }
                else
                {
                    response = new ServerResponse(userid, Response.InvalidPassword);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                response = new ServerResponse(userid, Response.ServerError);
                throw ex;
            }

            return(response);
        }