private void GetPasswordHelper(bool requireQA, bool enablePasswordRetrieval, string answer) { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", requireQA ? "true" : "false"); config.Add("enablePasswordRetrieval", enablePasswordRetrieval ? "true" : "false"); config.Add("passwordFormat", "clear"); config.Add("applicationName", "/"); provider.Initialize(null, config); provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, null, out status); try { string password = provider.GetPassword("foo", answer); if (!enablePasswordRetrieval) { Assert.Fail("This should have thrown an exception"); } Assert.AreEqual("barbar!", password); } catch (ProviderException) { if (requireQA && answer != null) { Assert.Fail("This should not have thrown an exception"); } } }
public void CreateUserWithLeadingAndTrailingSpaces() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("autogenerateschema", "true"); config.Add("applicationName", "/"); provider.Initialize(null, config); MembershipCreateStatus status; MembershipUser muser1 = provider.CreateUser(" with trailing space ", "dummypassword1!", "[email protected]", "yes", "yes", true, null, out status); Assert.NotEqual(null, muser1); MembershipUser muser2 = provider.GetUser("with trailing space", false); Assert.NotEqual(null, muser1); Roles.CreateRole("SomeRole"); Assert.True(Roles.GetAllRoles().Length > 0); bool isInRole = Roles.IsUserInRole(muser2.UserName, "SomeRole"); Assert.False(isInRole); Roles.AddUserToRole(muser2.UserName, "SomeRole"); isInRole = Roles.IsUserInRole(muser2.UserName, "SomeRole"); Assert.True(isInRole); }
public void SchemaCheck() { for (int i = 0; i <= SchemaManager.Version; i++) { MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordFormat", "Clear"); if (i > 0) { for (int x = 1; x <= i; x++) { LoadSchema(x); } } try { provider.Initialize(null, config); Assert.False(i < SchemaManager.Version, "This should have failed"); } catch (ProviderException) { Assert.False(i == SchemaManager.Version, "This should not have failed"); } } }
protected void LoadSchema(int version) { if (version < 1) { return; } MySQLMembershipProvider provider = new MySQLMembershipProvider(); ResourceManager r = new ResourceManager("MySql.Web.Properties.Resources", typeof(MySQLMembershipProvider).Assembly); string schema = r.GetString(String.Format("schema{0}", version)); MySqlScript script = new MySqlScript(conn); script.Query = schema; try { script.Execute(); } catch (MySqlException ex) { if (ex.Number == 1050 && version == 7) { // Schema7 performs several renames of tables to their lowercase representation. // If the current server OS does not support renaming to lowercase, then let's just continue. script.Query = "UPDATE my_aspnet_schemaversion SET version=7"; script.Execute(); } } }
public void InitializeInvalidConnStringThrowsArgumentException() { Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string connStr = configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString; string fakeConnectionString = connStr.Replace("database", "fooKey"); try { configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString = fakeConnectionString; configFile.Save(); ConfigurationManager.RefreshSection("connectionStrings"); MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); provider.Initialize(null, config); } finally { configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString = connStr; configFile.Save(); ConfigurationManager.RefreshSection("connectionStrings"); } }
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); }
public void DeleteUser() { execSQL(@"delete from my_aspnet_membership; delete from my_aspnet_users;"); CreateUserWithFormat(MembershipPasswordFormat.Hashed); Assert.True(provider.DeleteUser("foo", true)); DataTable table = FillTable("SELECT * FROM my_aspnet_membership"); Assert.AreEqual(0, table.Rows.Count); table = FillTable("SELECT * FROM my_aspnet_users"); Assert.AreEqual(0, table.Rows.Count); CreateUserWithFormat(MembershipPasswordFormat.Hashed); provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); provider.Initialize(null, config); Assert.True(Membership.DeleteUser("foo", false)); table = FillTable("SELECT * FROM my_aspnet_membership"); Assert.AreEqual(0, table.Rows.Count); table = FillTable("SELECT * FROM my_aspnet_users"); Assert.AreEqual(1, table.Rows.Count); }
internal protected void LoadSchema(int version) { if (version < 1) { return; } MySQLMembershipProvider provider = new MySQLMembershipProvider(); string schema = LoadResource($"MySql.Web.Properties.schema{version}.sql"); MySqlScript script = new MySqlScript(Connection); script.Query = schema.ToString(); try { script.Execute(); } catch (MySqlException ex) { if (ex.Number == 1050 && version == 7) { // Schema7 performs several renames of tables to their lowercase representation. // If the current server OS does not support renaming to lowercase, then let's just continue. script.Query = "UPDATE my_aspnet_schemaversion SET version=7"; script.Execute(); } } }
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 InitializeInvalidConnStringThrowsArgumentException() { Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string connStr = configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString; string fakeConnectionString = connStr.Replace("database", "fooKey"); try { configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString = fakeConnectionString; configFile.Save(); ConfigurationManager.RefreshSection("connectionStrings"); MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); Exception ex = Assert.Throws <ArgumentException>(() => provider.Initialize(null, config)); Assert.Equal("Keyword not supported.\r\nParameter name: fookey", ex.Message); } finally { configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString = connStr; configFile.Save(); ConfigurationManager.RefreshSection("connectionStrings"); } }
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.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!")); }
public void GetPasswordWithWrongAnswer() { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", "true"); config.Add("enablePasswordRetrieval", "true"); config.Add("passwordFormat", "Encrypted"); config.Add("applicationName", "/"); provider.Initialize(null, config); provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, null, out status); MySQLMembershipProvider provider2 = new MySQLMembershipProvider(); NameValueCollection config2 = new NameValueCollection(); config2.Add("connectionStringName", "LocalMySqlServer"); config2.Add("requiresQuestionAndAnswer", "true"); config2.Add("enablePasswordRetrieval", "true"); config2.Add("passwordFormat", "Encrypted"); config2.Add("applicationName", "/"); provider2.Initialize(null, config2); Assert.Throws <MembershipPasswordException>(() => provider2.GetPassword("foo", "wrong")); //Cleanup provider.DeleteUser("foo", true); }
public void CreateUserWithNoQA() { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", "true"); config.Add("passwordFormat", "clear"); config.Add("applicationName", "/"); provider.Initialize(null, config); try { provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", null, true, null, out status); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.StartsWith("Password answer supplied is invalid")); } try { provider.CreateUser("foo", "barbar!", "*****@*****.**", "", "blue", true, null, out status); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.StartsWith("Password question supplied is invalid")); } }
public void GetEncryptedPassword() { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", "false"); config.Add("enablePasswordRetrieval", "true"); config.Add("passwordFormat", "encrypted"); config.Add("applicationName", "/"); provider.Initialize(null, config); MembershipUser user = provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status); Assert.NotNull(user); string pw = provider.GetPassword("foo", null); Assert.Equal("barbar!", pw); //Cleanup provider.DeleteUser("foo", true); }
public void InitializeInvalidConnStringThrowsArgumentException() { MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); var badConnectionString = ConnectionString + ";fookey=boo"; config.Add("connectionString", badConnectionString); Exception ex = Assert.Throws <ArgumentException>(() => provider.Initialize(null, config)); Assert.AreEqual("Option not supported.\r\nParameter name: fookey", ex.Message); }
public RoleManagement() { membershipProvider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); membershipProvider.Initialize(null, config); roleProvider = new MySQLRoleProvider(); roleProvider.Initialize(null, config); }
private void GetPasswordHelper(bool requireQA, bool enablePasswordRetrieval, string answer) { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", requireQA ? "true" : "false"); config.Add("enablePasswordRetrieval", enablePasswordRetrieval ? "true" : "false"); config.Add("passwordFormat", "clear"); config.Add("applicationName", "/"); config.Add("writeExceptionsToEventLog", "false"); provider.Initialize(null, config); provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, null, out status); string password = string.Empty; if (!enablePasswordRetrieval) { if (requireQA && answer != null) { Exception ex = Assert.Throws <MembershipPasswordException>(() => provider.GetPassword("foo", answer)); } else { Exception ex = Assert.Throws <ProviderException>(() => provider.GetPassword("foo", answer)); Assert.Equal(ex.Message, "Password Retrieval Not Enabled."); } } else { if (requireQA && answer != null) { provider.GetPassword("foo", answer); } else if (requireQA && answer == null) { //Incorrect password answer. Assert.Throws <MembershipPasswordException>(() => provider.GetPassword("foo", answer)); } else { password = provider.GetPassword("foo", answer); Assert.Equal("barbar!", password); } } //Cleanup provider.DeleteUser("foo", true); }
public void SetFixture(SetUpWeb data) { st = data; st.execSQL("DROP TABLE IF EXISTS mysql_membership"); st.execSQL("DROP TABLE IF EXISTS mysql_roles"); membershipProvider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); membershipProvider.Initialize(null, config); }
public override void Setup() { base.Setup(); execSQL("DROP TABLE IF EXISTS mysql_membership"); execSQL("DROP TABLE IF EXISTS mysql_roles"); membershipProvider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); membershipProvider.Initialize(null, config); }
protected void LoadSchema(int version) { if (version < 1) { return; } MySQLMembershipProvider provider = new MySQLMembershipProvider(); ResourceManager r = new ResourceManager("MySql.Web.Properties.Resources", typeof(MySQLMembershipProvider).Assembly); string schema = r.GetString(String.Format("schema{0}", version)); //MySqlScript script = new MySqlScript(conn); //script.Query = schema; //script.Execute(); }
public void IsUserInRoleCrossDomain() { MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config1 = new NameValueCollection(); config1.Add("connectionStringName", "LocalMySqlServer"); config1.Add("applicationName", "/"); config1.Add("passwordStrengthRegularExpression", "bar.*"); config1.Add("passwordFormat", "Clear"); provider.Initialize(null, config1); 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); roleProvider = new MySQLRoleProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); roleProvider.Initialize(null, config); MySQLRoleProvider r2 = new MySQLRoleProvider(); NameValueCollection configr2 = new NameValueCollection(); configr2.Add("connectionStringName", "LocalMySqlServer"); configr2.Add("applicationName", "/myapp"); r2.Initialize(null, configr2); roleProvider.CreateRole("Administrator"); roleProvider.AddUsersToRoles(new string[] { "foo" }, new string[] { "Administrator" }); Assert.False(r2.IsUserInRole("foo", "Administrator")); roleProvider.DeleteRole("Administrator", false); Assert.AreEqual(0, roleProvider.GetAllRoles().Length); //Cleanup provider.DeleteUser("foo", true); }
public void AutoGenerateSchema() { MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("autogenerateschema", "true"); config.Add("applicationName", "/"); config.Add("passwordFormat", "Clear"); provider.Initialize(null, config); MembershipCreateStatus status; MembershipUser user = provider.CreateUser("boo", "password", "*****@*****.**", "question", "answer", true, null, out status); }
public void SchemaNotPresent() { MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordFormat", "Clear"); try { provider.Initialize(null, config); Assert.Fail("Should have failed"); } catch (ProviderException) { } }
public void MinRequiredAlpha() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("minRequiredNonalphanumericCharacters", "3"); provider.Initialize(null, config); MembershipCreateStatus status; MembershipUser user = provider.CreateUser("foo", "pw!pass", "email", null, null, true, null, out status); Assert.IsNull(user); user = provider.CreateUser("foo", "pw!pa!!", "email", null, null, true, null, out status); Assert.IsNotNull(user); }
public void ResetPassword() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordStrengthRegularExpression", "bar.*"); config.Add("passwordFormat", "Clear"); config.Add("requiresQuestionAndAnswer", "false"); provider.Initialize(null, config); MembershipCreateStatus status; provider.CreateUser("foo", "bar!bar", null, null, null, true, null, out status); MembershipUser u = provider.GetUser("foo", false); string newpw = provider.ResetPassword("foo", null); }
public void CreateUserWithNoQA() { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", "true"); config.Add("passwordFormat", "clear"); config.Add("applicationName", "/"); provider.Initialize(null, config); Exception ex = Assert.Throws <ArgumentException>(() => provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", null, true, null, out status)); Assert.True(ex.Message.StartsWith("Password answer supplied is invalid", StringComparison.OrdinalIgnoreCase)); ex = Assert.Throws <ArgumentException>(() => provider.CreateUser("foo", "barbar!", "*****@*****.**", "", "blue", true, null, out status)); Assert.True(ex.Message.StartsWith("Password question supplied is invalid", StringComparison.OrdinalIgnoreCase)); }
public void CreateUserWithErrors() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordStrengthRegularExpression", "bar.*"); config.Add("passwordFormat", "Hashed"); provider.Initialize(null, config); // first try to create a user with a password not long enough MembershipCreateStatus status; MembershipUser user = provider.CreateUser("foo", "xyz", "*****@*****.**", null, null, true, null, out status); Assert.Null(user); Assert.Equal(MembershipCreateStatus.InvalidPassword, status); // now with not enough non-alphas user = provider.CreateUser("foo", "xyz1234", "*****@*****.**", null, null, true, null, out status); Assert.Null(user); Assert.Equal(MembershipCreateStatus.InvalidPassword, status); // now one that doesn't pass the regex test user = provider.CreateUser("foo", "xyzxyz!", "*****@*****.**", null, null, true, null, out status); Assert.Null(user); Assert.Equal(MembershipCreateStatus.InvalidPassword, status); // now one that works user = provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status); Assert.NotNull(user); Assert.Equal(MembershipCreateStatus.Success, status); //Cleanup provider.DeleteUser("foo", true); }
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")); }
public void DeleteUser() { CreateUserWithHashedPassword(); Assert.IsTrue(provider.DeleteUser("foo", true)); DataTable table = GetMembers(); Assert.AreEqual(0, table.Rows.Count); CreateUserWithHashedPassword(); provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); provider.Initialize(null, config); Assert.IsTrue(Membership.DeleteUser("foo", true)); table = GetMembers(); Assert.AreEqual(0, table.Rows.Count); }
public void TestCreateUserOverrides() { try { // we have to initialize the provider so the db will exist provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); provider.Initialize(null, config); Membership.CreateUser("foo", "bar"); int records; MembershipUserCollection users = Membership.FindUsersByName("F%", 0, 10, out records); Assert.AreEqual(1, records); Assert.AreEqual("foo", users["foo"].UserName); Membership.CreateUser("test", "bar", "*****@*****.**"); users = Membership.FindUsersByName("T%", 0, 10, out records); Assert.AreEqual(1, records); Assert.AreEqual("test", users["test"].UserName); } catch (Exception ex) { Assert.Fail(ex.Message); } }
private static MySqlSimpleMembershipProvider CreateSimpleMembershipProvider(string name, MySQLMembershipProvider currentDefault) { MySqlSimpleMembershipProvider simpleProvider = new MySqlSimpleMembershipProvider(currentDefault); NameValueCollection config = new NameValueCollection(); simpleProvider.Initialize(name, config); return(simpleProvider); }
public void GetPassword() { 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); string password = provider.GetPassword("foo", null); Assert.AreEqual("pass", password); } catch (Exception ex) { Assert.Fail(ex.Message); } }
protected override void Setup() { base.Setup(); execSQL("DROP TABLE IF EXISTS mysql_membership"); execSQL("DROP TABLE IF EXISTS mysql_roles"); membershipProvider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); membershipProvider.Initialize(null, config); }
public override void ProjectFinishedGenerating(Project project) { if (project != null) { VSProject vsProj = project.Object as VSProject; var tables = new List <string>(); Settings.Default.MVCWizardConnection = WizardForm.ServerExplorerConnectionSelected; Settings.Default.Save(); if (_generalPane != null) { _generalPane.Activate(); } SendToGeneralOutputWindow("Starting project generation..."); //Updating project references try { vsProj.References.Add("MySql.Data"); } catch { var infoResult = InfoDialog.ShowDialog( InfoDialogProperties.GetOkCancelDialogProperties( InfoDialog.InfoType.Warning, Resources.MySqlDataProviderPackage_ConnectorNetNotFoundError, @"To use it you must download and install the MySQL Connector/Net package from http://dev.mysql.com/downloads/connector/net/", Resources.MySqlDataProviderPackage_ClickOkOrCancel)); if (infoResult.DialogResult == DialogResult.OK) { ProcessStartInfo browserInfo = new ProcessStartInfo("http://dev.mysql.com/downloads/connector/net/"); System.Diagnostics.Process.Start(browserInfo); } } double version = double.Parse(WizardForm.Wizard.GetVisualStudioVersion()); if (version >= 12.0) { References refs = vsProj.References; foreach (Reference item in refs) { switch (item.Name) { case "System.Web.Razor": if (item.Version.Equals("1.0.0.0")) { vsProj.References.Find("System.Web.Razor").Remove(); } break; case "System.Web.WebPages": vsProj.References.Find("System.Web.WebPages").Remove(); break; case "System.Web.Mvc": vsProj.References.Find("System.Web.Mvc").Remove(); break; case "System.Web.Helpers": vsProj.References.Find("System.Web.Helpers").Remove(); break; } } vsProj.References.Add("System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"); vsProj.References.Add("System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"); vsProj.References.Add("System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"); vsProj.References.Add("System.Web.Razor"); #if NET_40_OR_GREATER vsProj.Project.Save(); #endif } AddNugetPackage(vsProj, JQUERY_PKG_NAME, JQUERY_VERSION, false); var packagesPath = Path.Combine(Path.GetDirectoryName(ProjectPath), @"Packages\jQuery." + JQUERY_VERSION + @"\Content\Scripts"); CopyPackageToProject(vsProj, ProjectPath, packagesPath, "Scripts"); if (WizardForm.SelectedTables != null && WizardForm.DEVersion != DataEntityVersion.None) { WizardForm.SelectedTables.ForEach(t => tables.Add(t.Name)); SendToGeneralOutputWindow("Generating Entity Framework model..."); if (tables.Count > 0) { if (WizardForm.DEVersion == DataEntityVersion.EntityFramework5) { CurrentEntityFrameworkVersion = ENTITY_FRAMEWORK_VERSION_5; } else if (WizardForm.DEVersion == DataEntityVersion.EntityFramework6) { CurrentEntityFrameworkVersion = ENTITY_FRAMEWORK_VERSION_6; } AddNugetPackage(vsProj, ENTITY_FRAMEWORK_PCK_NAME, CurrentEntityFrameworkVersion, true); string modelPath = Path.Combine(ProjectPath, "Models"); GenerateEntityFrameworkModel(project, vsProj, new MySqlConnection(WizardForm.ConnectionStringForModel), WizardForm.ModelName, tables, modelPath); GenerateMVCItems(vsProj); if (WizardForm.DEVersion == DataEntityVersion.EntityFramework6) { project.DTE.SuppressUI = true; project.Properties.Item("TargetFrameworkMoniker").Value = ".NETFramework,Version=v4.5"; } } } else { string indexPath = Language == LanguageGenerator.CSharp ? (string)(FindProjectItem(FindProjectItem(FindProjectItem(vsProj.Project.ProjectItems, "Views").ProjectItems, "Home").ProjectItems, "Index.cshtml").Properties.Item("FullPath").Value) : (string)(FindProjectItem(FindProjectItem(FindProjectItem(vsProj.Project.ProjectItems, "Views").ProjectItems, "Home").ProjectItems, "Index.vbhtml").Properties.Item("FullPath").Value); string contents = File.ReadAllText(indexPath); contents = contents.Replace("$catalogList$", String.Empty); File.WriteAllText(indexPath, contents); } var webConfig = new MySql.Data.VisualStudio.WebConfig.WebConfig(ProjectPath + @"\web.config"); SendToGeneralOutputWindow("Starting provider configuration..."); try { try { string configPath = ProjectPath + @"\web.config"; if (WizardForm.CreateAdministratorUser) { SendToGeneralOutputWindow("Creating administrator user..."); using (AppConfig.Load(configPath)) { var configFile = new FileInfo(configPath); var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); System.Configuration.Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); try { if (!WizardForm.IncludeSensitiveInformation) { ConnectionStringsSection connectionStringsection = config.GetSection("connectionStrings") as ConnectionStringsSection; if (connectionStringsection != null) { connectionStringsection.ConnectionStrings[WizardForm.ConnectionStringNameForAspNetTables].ConnectionString = _fullconnectionstring; config.Save(); } } } catch { } MembershipSection section = (MembershipSection)config.GetSection("system.web/membership"); ProviderSettingsCollection settings = section.Providers; NameValueCollection membershipParams = settings[section.DefaultProvider].Parameters; var provider = new MySQLMembershipProvider(); provider.Initialize(section.DefaultProvider, membershipParams); //create the user MembershipCreateStatus status; if (!WizardForm.RequireQuestionAndAnswer) { provider.CreateUser(WizardForm.AdminName, WizardForm.AdminPassword, "*****@*****.**", null, null, true, null, out status); } else { provider.CreateUser(WizardForm.AdminName, WizardForm.AdminPassword, "*****@*****.**", WizardForm.UserQuestion, WizardForm.UserAnswer, true, null, out status); } } } // add creation of providers tables if (WizardForm.IncludeProfilesProvider) { var profileConfig = new ProfileConfig(); profileConfig.Initialize(webConfig); profileConfig.Enabled = true; profileConfig.DefaultProvider = "MySQLProfileProvider"; var options = new Options(); options.AppName = @"\"; options.AutoGenSchema = true; options.ConnectionStringName = WizardForm.ConnectionStringNameForAspNetTables; options.ConnectionString = WizardForm.ConnectionStringForAspNetTables; options.EnableExpireCallback = false; options.ProviderName = "MySQLProfileProvider"; options.WriteExceptionToLog = WizardForm.WriteExceptionsToLog; profileConfig.GenericOptions = options; profileConfig.DefaultProvider = "MySQLProfileProvider"; profileConfig.Save(webConfig); } if (WizardForm.IncludeRoleProvider) { var roleConfig = new RoleConfig(); roleConfig.Initialize(webConfig); roleConfig.Enabled = true; roleConfig.DefaultProvider = "MySQLRoleProvider"; var options = new Options(); options.AppName = @"\"; options.AutoGenSchema = true; options.ConnectionStringName = WizardForm.ConnectionStringNameForAspNetTables; options.ConnectionString = WizardForm.ConnectionStringForAspNetTables; options.EnableExpireCallback = false; options.ProviderName = "MySQLRoleProvider"; options.WriteExceptionToLog = WizardForm.WriteExceptionsToLog; roleConfig.GenericOptions = options; roleConfig.DefaultProvider = "MySQLRoleProvider"; roleConfig.Save(webConfig); } webConfig.Save(); } catch (Exception ex) { MySqlSourceTrace.WriteAppErrorToLog(ex, null, Resources.WebWizard_UserCreationError, true); } } catch (Exception ex) { MySqlSourceTrace.WriteAppErrorToLog(ex, true); } } SendToGeneralOutputWindow("Finished project generation."); WizardForm.Dispose(); }