Пример #1
0
        private void CreateUserWithFormat(MembershipPasswordFormat format)
        {
            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            config.Add("passwordStrengthRegularExpression", "bar.*");
            config.Add("passwordFormat", format.ToString());
            provider.Initialize(null, config);

            // create the user
            MembershipCreateStatus status;

            provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status);
            Assert.Equal(MembershipCreateStatus.Success, status);

            // verify that the password format is hashed.
            DataTable table = FillTable("SELECT * FROM my_aspnet_membership");
            MembershipPasswordFormat rowFormat =
                (MembershipPasswordFormat)Convert.ToInt32(table.Rows[0]["PasswordFormat"]);

            Assert.Equal(format, rowFormat);

            //  then attempt to verify the user
            Assert.True(provider.ValidateUser("foo", "barbar!"));
        }
Пример #2
0
        private void CreateUserWithFormat(MembershipPasswordFormat format)
        {
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            config.Add("passwordStrengthRegularExpression", "bar.*");
            config.Add("passwordFormat", format.ToString());
            provider.Initialize(null, config);

            // create the user
            MembershipCreateStatus status;

            provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status);
            Assert.AreEqual(MembershipCreateStatus.Success, status);

            // verify that the password format was saved
            var user = _db.GetCollection <User>(provider.CollectionName).FindOne(Query.EQ(provider.ElementNames.LowercaseUsername, "foo"));
            MembershipPasswordFormat rowFormat = user.PasswordFormat;

            Assert.AreEqual(format, rowFormat);

            //  then attempt to verify the user
            Assert.IsTrue(provider.ValidateUser("foo", "barbar!"));
        }
        /// <summary>
        /// Initializes a new <see cref="SqlMembershipProviderPasswordService"/> using the provided password format.
        /// </summary>
        /// <param name="passwordFormat">The password encryption method.</param>
        public SqlMembershipProviderPasswordService(MembershipPasswordFormat passwordFormat)
        {
            this.passwordFormat = passwordFormat;
             this.provider = new SqlMembershipProvider();

             var config = new NameValueCollection {
            { "minRequiredPasswordLength", "1" },
            { "minRequiredNonalphanumericCharacters", "0" },
            { "passwordFormat", passwordFormat.ToString() },
            { "passwordCompatMode", "Framework40" },
            { "connectionString" , "__foo__" }
             };

             this.provider.Initialize(null, config);
        }
Пример #4
0
        private void CreateUserWithFormat(MembershipPasswordFormat format)
        {
            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            config.Add("passwordStrengthRegularExpression", "bar.*");
            config.Add("passwordFormat", format.ToString());
            provider.Initialize(null, config);

            // create the user
            MembershipCreateStatus status;
            provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status);
            Assert.AreEqual(MembershipCreateStatus.Success, status);

            // verify that the password format is hashed.
            DataTable table = FillTable("SELECT * FROM my_aspnet_Membership");
            MembershipPasswordFormat rowFormat =
                (MembershipPasswordFormat)Convert.ToInt32(table.Rows[0]["PasswordFormat"]);
            Assert.AreEqual(format, rowFormat);

            //  then attempt to verify the user
            Assert.IsTrue(provider.ValidateUser("foo", "barbar!"));
        }
        private void CreateUserWithFormat(MembershipPasswordFormat format)
        {
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            config.Add("passwordStrengthRegularExpression", "bar.*");
            config.Add("passwordFormat", format.ToString());
            provider.Initialize(null, config);

            // create the user
            MembershipCreateStatus status;
            provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status);
            Assert.AreEqual(MembershipCreateStatus.Success, status);

            // verify that the password format was saved
            var user = _db.GetCollection<User>(provider.CollectionName).FindOne(Query.EQ(provider.ElementNames.LowercaseUsername, "foo"));
            MembershipPasswordFormat rowFormat = user.PasswordFormat;
            Assert.AreEqual(format, rowFormat);

            //  then attempt to verify the user
            Assert.IsTrue(provider.ValidateUser("foo", "barbar!"));
        }
        public void CreateUserWithFormat(MembershipPasswordFormat format)
        {
            var mongoProvider = new MongoMembershipProvider();
            var config = new NameValueCollection
            {
                {"connectionStringName", ConfigurationManager.ConnectionStrings[0].Name},
                {"passwordFormat", format.ToString()}
            };
            mongoProvider.Initialize("MongoMembershipProvider", config);

            // create the user
            MembershipCreateStatus status;
            var user = mongoProvider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status);
            status.Should().Be(MembershipCreateStatus.Success);
            user.Should().NotBeNull();

            // verify that the password format was saved
            var collection = this.MongoDatabase.GetCollection<User>(mongoProvider.UserCollectionName);
            var userFromDB = collection.FindOneById(BsonValue.Create(user.ProviderUserKey));
            userFromDB.PasswordFormat.Should().Be(format);

            // then attempt to verify the user
            mongoProvider.ValidateUser("foo", "barbar!").Should().BeTrue();
        }