public ValidateUser ( string username, string password ) : bool | ||
username | string | The name of the user to validate. |
password | string | The password for the specified user. |
Результат | bool |
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.IsTrue(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.IsTrue(status == MembershipCreateStatus.Success); provider.ApplicationName = "/myapp"; Assert.IsFalse(provider.ValidateUser("foo", "bar!bar")); Assert.IsTrue(provider.ValidateUser("foo2", "foo!foo")); }
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!")); }
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.AreEqual(false, worked); }