Inheritance: MembershipProvider
 public void Initialize(string applicationName, SqlConnectionHolder holder, SqlMembershipProvider sqlMembershipProvider, int commandTimeout)
 {
     CommandTimeout = commandTimeout;
     Holder = holder;
     Provider = sqlMembershipProvider;
     ApplicationName = applicationName;
 }
        public override MembershipProvider GetProvider()
        {
            DatabaseUtil.CreateTestDatabase(FixtureConstants.SqlMembershipProviderDatabaseName);

            var result = new SqlMembershipProvider();

            return result;
        }
        /// <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);
        }
        public override MembershipProvider GetProvider()
        {
            string tempPath = Properties.Settings.Default.AccessibleTempPath;
            string databaseMdfPath = Path.Combine(tempPath, @"RavenDBMembershipTestSqlDatabase\DatabaseFile.mdf");

            if (!Directory.Exists(tempPath))
                Directory.CreateDirectory(tempPath);

            DatabaseInitialization.DetachDatabase(FixtureConstants.DatabaseName);
            DatabaseInitialization.RecreateDatabase(FixtureConstants.DatabaseName, databaseMdfPath);
            DatabaseInitialization.RunSqlMembershipCreationScript(FixtureConstants.DatabaseName);

            var result = new SqlMembershipProvider();

            return result;
        }
Exemplo n.º 5
0
        public DataSet GetData()
        {
            _connetionStringBuilder = new SqlConnectionStringBuilder();

            _connetionStringBuilder["Data Source"] = "localhost\\SQLExpress";

            _connetionStringBuilder["integrated Security"] = true;
            _connetionStringBuilder["Initial Catalog"] = "STMEMBERSHIP";
            _connetionStringBuilder["Asynchronous Processing"] = true;

            DataSet dataSet = new DataSet();
            using (SqlConnection connection = new SqlConnection( _connetionStringBuilder.ConnectionString ))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("SELECT * FROM dbo.aspnet_Users", connection))
                {
                    SqlDataAdapter adapter = new SqlDataAdapter(command);
                    adapter.Fill(dataSet);
                }
            }
            
			SqlMembershipProvider test = new SqlMembershipProvider();

            //System.Collections.Specialized.NameValueCollection nc = new System.Collections.Specialized.NameValueCollection();
            //nc.Add("connectionStringName", "StudyMateConnectionString");
            //nc.Add("applicationName", "/STMate");
            //nc.Add("requiresQuestionAndAnswer", "false");

            //test.Initialize("StudyMateMembershipProvider", nc);


            //System.Collections.Specialized.NameValueCollection nameColl = new System.Collections.Specialized.NameValueCollection();

            //nameColl.Add("connectionStringName", "StudyMateConnectionString");
            //nameColl.Add("applicationName", "/STMate");
            //nameColl.Add("requiresQuestionAndAnswer", "false");

            //defaultMembership.Initialize("StudyMateMembershipProvider", nameColl);


            //int Total= 0;
            //MembershipUserCollection col = defaultMembership.GetAllUsers(0, 10, out Total);

            //System.Collections.IEnumerator en =  col.GetEnumerator();

            //en.Reset();
            //while (en.MoveNext())
            //{
            //    MembershipUser firest = (MembershipUser)en.Current;
            //    Console.WriteLine(firest.Email);
            //}

            //int Total = 0;
            //MembershipUserCollection col = test.GetAllUsers(0, 10, out Total);

            //System.Collections.IEnumerator en = col.GetEnumerator();

            //en.Reset();
            //while (en.MoveNext())
            //{
            //    MembershipUser firest = (MembershipUser)en.Current;
            //    Console.WriteLine(firest.Email);
            //}
            //MembershipUser user = (MembershipUser)test.GetUser (userName, false);

            //public ActionResult ExpireSession()
            //{
            //    string sessionId = Session.SessionID;
            //    Session.Abandon();
            //    return new ContentResult()
            //    {
            //        Content = "Session '" + sessionId + "' abandoned at " + DateTime.Now
            //    };
            //}
            //this.Context.Application.Lock();
            //this.Context.Application.UnLock();

            //this.Context.Response.Redirect("http://www.google.co.kr");

            return dataSet;
        }
Exemplo n.º 6
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            Errors.Items.Clear();

            string serverType = ServerTypeDrop.SelectedValue;
            DbServer serverTypeParsed;
            if (!Enum.TryParse<DbServer>(serverType, out serverTypeParsed))
            {
                Errors.Items.Add("Please, choose the type of database engine you wish to use.");
                return;
            }

            // initial testing of the database connection before we attempt to create the main schema
            IBaseDriver drv = null;
            switch (serverTypeParsed)
            {
                case DbServer.MySql:
                    drv = new BaseDriverMySql(SystemConnstringTextBox.Text);
                    break;
                case DbServer.MsSql:
                    drv = new BaseDriverMsSql(SystemConnstringTextBox.Text);
                    break;
            }

            try
            {
                drv.TestConnection();
                drv.TestDatabaseIsEmpty();
            }
            catch (Exception ex)
            {
                Errors.Items.Add(ex.Message);
                return;
            }

            if (UsernameTextBox.Text == "")
            {
                Errors.Items.Add("Please, insert the initial user's name");
                return;
            }

            if (PasswordTextBox.Text.Length < 7)
            {
                Errors.Items.Add("The password must be at least 7 characters long.");
                return;
            }

            if (PasswordTextBox.Text != RetypePasswordTextBox.Text)
            {
                Errors.Items.Add("The passwords do not match.");
                return;
            }

            try
            {
                System.Net.Mail.MailAddress address = new System.Net.Mail.MailAddress(MailTextBox.Text);
            }
            catch (FormatException fe)
            {
                Errors.Items.Add(fe.Message);
                return;
            }

            // run the schema dump script
            switch (serverTypeParsed)
            {
                case DbServer.MySql:
                    MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(SystemConnstringTextBox.Text);
                    try
                    {
                        MySql.Data.MySqlClient.MySqlScript script = new MySql.Data.MySqlClient.MySqlScript(connection);
                        string scriptText = File.ReadAllText(HttpContext.Current.Server.MapPath(CC.MYSQL_SCHEMA_FILE_PATH));
                        script.Query = scriptText;
                        script.Query = scriptText;
                        connection.Open();
                        script.Execute();
                        connection.Clone();
                    }
                    catch (Exception esql1)
                    {
                        Errors.Items.Add(esql1.Message);
                        connection.Close();
                        return;
                    }
                    break;

                case DbServer.MsSql:
                    SqlConnection conn = new SqlConnection(SystemConnstringTextBox.Text);
                    try
                    {

                        string query = File.ReadAllText(HttpContext.Current.Server.MapPath(CC.MSSQL_SCHEMA_FILE_PATH));
                        Microsoft.SqlServer.Management.Smo.Server sqlServer = new Server(new ServerConnection(conn));
                        conn.Open();
                        sqlServer.ConnectionContext.ExecuteNonQuery(query);
                        conn.Close();

                        SqlMembershipProvider mssqlProvider = new SqlMembershipProvider();

                    }
                    catch (Exception esql2)
                    {
                        Errors.Items.Add(esql2.Message);
                        conn.Close();
                        return;
                    }
                    break;
            }

            var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
            var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");

            System.Web.Security.MembershipProvider membership = null;

            string username = UsernameTextBox.Text;
            string password = PasswordTextBox.Text;
            string mail = MailTextBox.Text;

            MembershipCreateStatus status;

            // rewrite the connection in the database and reload the connstring section, also set the defaultProvidder for the membership tag
            switch (serverTypeParsed)
            {
                case DbServer.MySql:
                    section.ConnectionStrings["MySqlServer"].ConnectionString = SystemConnstringTextBox.Text;
                    configuration.AppSettings.Settings["ServerType"].Value = "MySql";
                    configuration.Save();
                    SetDefaultMembershipProvider("MySqlMembershipProvider");

                    // remove the readonly attribute of the connection string variable of the connfiguration

                    var settingsMy = ConfigurationManager.ConnectionStrings["MsSqlServer"];
                    var fiMy = typeof( ConfigurationElement ).GetField( "_bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic );
                    fiMy.SetValue(settingsMy, false);
                    settingsMy.ConnectionString = SystemConnstringTextBox.Text;

                    membership = Membership.Providers["MySqlMembershipProvider"];

                    membership.CreateUser(username, password, mail, "Dummy question", "Dummy answer", true, 1, out status);
                    break;

                case DbServer.MsSql:
                    section.ConnectionStrings["MsSqlServer"].ConnectionString = SystemConnstringTextBox.Text;
                    configuration.AppSettings.Settings["ServerType"].Value = "MsSql";
                    configuration.Save();
                    SetDefaultMembershipProvider("MsSqlMembershipProvider");

                    // remove the readonly attribute of the connection string variable of the connfiguration
                    var settings = ConfigurationManager.ConnectionStrings["MsSqlServer"];
                    var fi = typeof( ConfigurationElement ).GetField( "_bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic );
                    fi.SetValue(settings, false);
                    settings.ConnectionString = SystemConnstringTextBox.Text;

                    membership = Membership.Providers["MsSqlMembershipProvider"];

                    // generate a ProviderUserKey
                    Random rand = new Random();
                    Guid key = new Guid(rand.Next(), 2, 3, new byte[] { 10, 20, 30, 40, 50, 60, 70, 80 });
                    ((SqlMembershipProvider)membership).CreateUser(username, password, mail, "Dummy question", "Dummy answer", true, key, out status);
                    break;
            }

            int totalUsers;
            MembershipUser user = membership.FindUsersByName(username, 0, 1, out totalUsers)[username];
            SystemDriver sysDriver = new SystemDriver(drv);
            sysDriver.SetUserRights((user.ProviderUserKey), null, 11110);

            // Set FirstRun to false. This cannot be done by the first configuration object - it wil
            // not like the configuration file since it has been modified by SetDefaultMembershipProvider
            // in the meantime.
            var config2 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
            config2.AppSettings.Settings["FirstRun"].Value = "False";
            System.Web.Configuration.WebConfigurationManager.AppSettings["FirstRun"] = "False";
            config2.Save();

            Errors.Items.Add("Done.");
            Response.RedirectToRoute("DefaultRoute");
        }
 private void InitSqlProvider()
 {
     MembershipSection membershipSection = GetConfigMembershipSection();
     string sqlProviderName = membershipSection.Providers[this.Name].Parameters["sqlProviderName"];
     _SqlProvider = (SqlMembershipProvider)Membership.Providers[sqlProviderName];
 }