コード例 #1
0
ファイル: User.cs プロジェクト: RyanOConnor/MyCrawler
        public bool ChangePassword(byte[] newPassword)
        {
            byte[] saltedHash = Authorize.GenerateSaltedHash(newPassword, password.salt);
            if (Authorize.IsValidHash(saltedHash, password.hash))
            {
                return(false);
            }
            foreach (Password prevPass in previousPasswords)
            {
                saltedHash = Authorize.GenerateSaltedHash(newPassword, prevPass.salt);
                if (Authorize.IsValidHash(saltedHash, prevPass.hash))
                {
                    return(false);
                }
            }
            byte[] salt = Authorize.GenerateSalt();
            saltedHash = Authorize.GenerateSaltedHash(newPassword, salt);
            Password newPass = new Password(saltedHash, salt);

            previousPasswords.Add(this.password);
            this.password = newPass;

            return(true);
        }
コード例 #2
0
ファイル: ServiceApi.cs プロジェクト: RyanOConnor/MyCrawler
        public Tuple <ServerResponse, ObjectId> CreateNewAccount(string username, string password)
        {
            Tuple <ServerResponse, ObjectId> response;

            try
            {
                if (Authorize.PassesGuidelines(password))
                {
                    byte[]   passBytes  = Encoding.UTF8.GetBytes(password);
                    byte[]   salt       = Authorize.GenerateSalt();
                    byte[]   saltedHash = Authorize.GenerateSaltedHash(passBytes, salt);
                    Password pass       = new Password(saltedHash, salt);
                    User     newUser    = new User(username.ToLower(), pass);
                    try
                    {
                        UserManager.Instance.SaveUser(newUser);
                        response = new Tuple <ServerResponse, ObjectId>(ServerResponse.Success, newUser.id);
                    }
                    catch (MongoWriteConcernException ex)
                    {
                        WriteLog(ex);
                        response = new Tuple <ServerResponse, ObjectId>(ServerResponse.UsernameAlreadyExists, ObjectId.Empty);
                    }
                }
                else
                {
                    response = new Tuple <ServerResponse, ObjectId>(ServerResponse.UsernameAlreadyExists, ObjectId.Empty);
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex);
                response = new Tuple <ServerResponse, ObjectId>(ServerResponse.ServerError, ObjectId.Empty);
            }
            return(response);
        }