public static void InitializePassword(this MemberPassword security, string password)
        {
            security.SaltValue = Guid.NewGuid();

            var passwordHelper = new PasswordHelper(security.SaltValue);

            security.Password = passwordHelper.Hash(password);
        }
예제 #2
0
        public void Hash_Test_Pass()
        {
            var saltValue = Guid.Parse("06099cc8-30da-4918-be0f-a06316de4a2d");
            var unhashedValue = "Password123!";
            var passwordHelper = new PasswordHelper(saltValue);
            var hashedValue = passwordHelper.Hash(unhashedValue);
            var expected = "vCu+DrCimRsT9SXLCM7JlbdVJWiz5KElucGLB8ALoqcCnyV8KPI8pejwzQuZ6yn52/r5eXN+4ItgEtORj5LPtQ==";

            Assert.AreEqual(expected, hashedValue);
        }
        public static bool Authenticate(this Member member, string password)
        {
            var returnValue = false;

            if (member.Exists())
            {
                if (member.IsActive)
                {
                    if (member.ConfirmedRegistration())
                    {
                        var passwordHelper = new PasswordHelper(member.Security.SaltValue);
                        var hashedPassword = passwordHelper.Hash(password);

                        if(string.Equals(hashedPassword, member.Security.Password, System.StringComparison.CurrentCulture))
                        {
                            returnValue = true;
                        }
                    }
                }
            }

            return returnValue;
        }