public void UserDatesNotInUtc()
        {
            var testProv = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            config.Add("dateTimeUseUtc", "False");
            testProv.Initialize(null, config);

            var userCreation = DateTime.Now;
            // create the user
            MembershipCreateStatus status;
            var user = testProv.CreateUser("nab", "barbar!", "*****@*****.**", null, null, true, null, out status);

            Assert.Equal(MembershipCreateStatus.Success, status);

            Assert.Equal(Truncate(userCreation, TimeSpan.TicksPerSecond), Truncate(user.CreationDate, TimeSpan.TicksPerSecond));
            Assert.Equal(Truncate(userCreation, TimeSpan.TicksPerSecond), Truncate(user.LastLoginDate, TimeSpan.TicksPerSecond));

            Thread.Sleep(30000);

            var lastLogin = DateTime.Now;
            var validated = testProv.ValidateUser("nab", "barbar!");

            Assert.Equal(true, validated);
            user = testProv.GetUser("nab", false);

            Assert.Equal(Truncate(lastLogin, TimeSpan.TicksPerSecond), Truncate(user.LastLoginDate, TimeSpan.TicksPerSecond));

            testProv.DeleteUser("nab", true);
        }
        public void CrossAppLogin()
        {
            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            config.Add("passwordStrengthRegularExpression", "bar.*");
            config.Add("passwordFormat", "Clear");
            provider.Initialize(null, config);
            MembershipCreateStatus status;

            provider.CreateUser("foo", "bar!bar", null, null, null, true, null, out status);

            MySQLMembershipProvider provider2 = new MySQLMembershipProvider();
            NameValueCollection     config2   = new NameValueCollection();

            config2.Add("connectionStringName", "LocalMySqlServer");
            config2.Add("applicationName", "/myapp");
            config2.Add("passwordStrengthRegularExpression", ".*");
            config2.Add("passwordFormat", "Clear");
            provider2.Initialize(null, config2);

            bool worked = provider2.ValidateUser("foo", "bar!bar");

            Assert.Equal(false, worked);

            //Cleanup
            provider.DeleteUser("foo", true);
        }
        private void CreateUserWithFormat(MembershipPasswordFormat format, bool dateTimeUseUtc)
        {
            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            config.Add("passwordStrengthRegularExpression", "bar.*");
            config.Add("passwordFormat", format.ToString());
            config.Add("dateTimeUseUtc", dateTimeUseUtc.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 = st.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!"));
        }
Пример #4
0
        public void ChangeAppName()
        {
            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            config.Add("passwordStrengthRegularExpression", "bar.*");
            config.Add("passwordFormat", "Clear");
            provider.Initialize(null, config);
            MembershipCreateStatus status;

            provider.CreateUser("foo", "bar!bar", null, null, null, true, null, out status);
            Assert.True(status == MembershipCreateStatus.Success);

            MySQLMembershipProvider provider2 = new MySQLMembershipProvider();
            NameValueCollection     config2   = new NameValueCollection();

            config2.Add("connectionStringName", "LocalMySqlServer");
            config2.Add("applicationName", "/myapp");
            config2.Add("passwordStrengthRegularExpression", "foo.*");
            config2.Add("passwordFormat", "Clear");
            provider2.Initialize(null, config2);
            provider2.CreateUser("foo2", "foo!foo", null, null, null, true, null, out status);
            Assert.True(status == MembershipCreateStatus.Success);

            provider.ApplicationName = "/myapp";
            Assert.False(provider.ValidateUser("foo", "bar!bar"));
            Assert.True(provider.ValidateUser("foo2", "foo!foo"));

            //Cleanup
            //provider.DeleteUser("foo2", true);
            //provider.DeleteUser("foo", true);

            //Cleanup
            MySqlHelper.ExecuteScalar(Connection, "DELETE FROM my_aspnet_users");
            MySqlHelper.ExecuteScalar(Connection, "DELETE FROM my_aspnet_membership");
        }
Пример #5
0
        public void ChangePassword()
        {
            CreateUserWithHashedPassword();
            try
            {
                provider.ChangePassword("foo", "barbar!", "bar2");
                Assert.Fail();
            }
            catch (ArgumentException ae1)
            {
                Assert.AreEqual("newPassword", ae1.ParamName);
                Assert.IsTrue(ae1.Message.Contains("length of parameter"));
            }

            try
            {
                provider.ChangePassword("foo", "barbar!", "barbar2");
                Assert.Fail();
            }
            catch (ArgumentException ae1)
            {
                Assert.AreEqual("newPassword", ae1.ParamName);
                Assert.IsTrue(ae1.Message.Contains("alpha numeric"));
            }

            // now test regex strength testing
            bool result = provider.ChangePassword("foo", "barbar!", "zzzxxx!");

            Assert.IsFalse(result);

            // now do one that should work
            result = provider.ChangePassword("foo", "barbar!", "barfoo!");
            Assert.IsTrue(result);

            provider.ValidateUser("foo", "barfoo!");
        }
Пример #6
0
        private void CreateUserWithFormat(MembershipPasswordFormat format)
        {
            provider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            config.Add("passwordFormat", format.ToString());
            provider.Initialize(null, config);

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

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

            //  then attempt to verify the user
            Assert.IsTrue(provider.ValidateUser("foo", "bar"));
        }
Пример #7
0
 public void GetNumberOfUsersOnline()
 {
     provider = new MySQLMembershipProvider();
     NameValueCollection config = new NameValueCollection();
     config.Add("connectionStringName", "LocalMySqlServer");
     config.Add("applicationName", "/");
     config.Add("enablePasswordRetrieval", "true");
     config.Add("passwordFormat", "Clear");
     config.Add("requireQuestionAndAnswer", "false");
     try
     {
         provider.Initialize(null, config);
         MembershipCreateStatus status;
         MembershipUser user = provider.CreateUser("foo", "pass", "*****@*****.**",
             null, null, true, null, out status);
         MembershipUser user2 = provider.CreateUser("foo2", "pass2", "*****@*****.**",
             null, null, true, null, out status);
         provider.ValidateUser("foo", "pass");
         provider.ValidateUser("foo2", "pass2");
         Assert.AreEqual(2, provider.GetNumberOfUsersOnline());
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message);
     }
 }