CreateUser() public abstract method

public abstract CreateUser ( string username, string password, string email, string pwdQuestion, string pwdAnswer, bool isApproved, object providerUserKey, MembershipCreateStatus &status ) : System.Web.Security.MembershipUser
username string
password string
email string
pwdQuestion string
pwdAnswer string
isApproved bool
providerUserKey object
status MembershipCreateStatus
return System.Web.Security.MembershipUser
Esempio n. 1
0
 public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer,
                                           bool isApproved, object providerUserKey, out MembershipCreateStatus status)
 {
     try
     {
         if (string.IsNullOrEmpty(email))
         {
             email = username;
         }
         MembershipUser u = GetUserByOpenId(username, false);
         if (u == null)
         {
             WebRequest request = HttpWebRequest.Create(Utility.NormalizeIdentityUrl(username));
             request.Method = "HEAD";
             var response = request.GetResponse();
             u = NonOpenIdMembershiProvider.CreateUser(username, password, email, passwordQuestion, passwordAnswer,
                                                       isApproved, providerUserKey, out status);
             LinkUserWithOpenId(username, u.ProviderUserKey);
             return(u);
         }
         else
         {
             status = MembershipCreateStatus.DuplicateUserName;
         }
     }
     catch (Exception ex)
     {
         status = MembershipCreateStatus.InvalidUserName;
     }
     return(null);
 }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer,
                                                  bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            MembershipUser u = GetUserByOpenId(username, false);

            if (u == null)
            {
                u = NonOpenIdMembershiProvider.CreateUser(username, password, email, passwordQuestion, passwordAnswer,
                                                          isApproved, providerUserKey, out status);
                LinkUserWithOpenId(username, u.ProviderUserKey);
                return(u);
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return(null);
        }
Esempio n. 3
0
        public void Can_create_account()
        {
            //System.Web.Security.MembershipProvider p = new WallBackend.Providers.nHibernateMembershipProvider();
            User u = new User()
            {
                Username = "******", Password = "******"
            };
            MembershipCreateStatus status;
            MembershipUser         mu = null;
            var s0 = Session;

            using (var t0 = s0.BeginTransaction())
            {
                mu = p.CreateUser(u.Username, u.Password, null, null, null, true, null, out status);
                Assert.IsNotNull(mu);
                Assert.AreEqual(u.Username, mu.UserName);
                Assert.AreEqual(status, MembershipCreateStatus.Success);
                t0.Rollback();
            }
        }
Esempio n. 4
0
        public MembershipCreateStatus CreateUser(string userName, string password, string pPostalAddress, string email)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("Value cannot be null or empty.", "userName");
            }
            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentException("Value cannot be null or empty.", "password");
            }
            if (String.IsNullOrEmpty(email))
            {
                throw new ArgumentException("Value cannot be null or empty.", "email");
            }

            MembershipCreateStatus status;

            _provider.CreateUser(userName, password, pPostalAddress, email, null, null, true, null, out status);
            return(status);
        }
        public override System.Web.Security.MembershipUser CreateUser(string username,
                                                                      string password,
                                                                      string email,
                                                                      string passwordQuestion,
                                                                      string passwordAnswer,
                                                                      bool isApproved,
                                                                      object providerUserKey,
                                                                      out MembershipCreateStatus status)
        {
            var membershipUser = PrimaryMembershipProvider.CreateUser(username,
                                                                      password,
                                                                      email,
                                                                      passwordQuestion,
                                                                      passwordAnswer,
                                                                      isApproved,
                                                                      providerUserKey,
                                                                      out status);

            if (membershipUser == null)
            {
                return(null);
            }
            if (status.Equals(MembershipCreateStatus.Success))
            {
                string userId;
                var    providerId = membershipUser.ProviderUserKey ?? membershipUser.UserName;
                try {
                    var guid = new Guid(providerId.ToString());
                    userId = guid.ToString("N");
                } catch (FormatException) {
                    userId = HashToString(providerId.ToString());
                }
                base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, userId, out status);
                if (!status.Equals(MembershipCreateStatus.Success))
                {
                    PrimaryMembershipProvider.DeleteUser(username, true);
                }
            }
            return(GetHybridMembershipUser(membershipUser));
        }
Esempio n. 6
0
        public static void CreateUser(string username, string password)
        {
            MembershipProvider provider = MembershipProvider.Instance();

            provider.CreateUser(username, password);
        }
        public void RegisterShouldCreateUserWithEmailAndPassword(FakeMembershipUser user, MembershipProvider membershipProvider, RegistrationInfo registrationInfo, string userProfile, AccountRepository repository)
        {
            user.ProviderName.Returns("fake");
              user.UserName.Returns("name");
              MembershipCreateStatus status;
              membershipProvider.CreateUser(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<object>(), out status).Returns(user);
              membershipProvider.GetUser(Arg.Any<string>(), Arg.Any<bool>()).Returns(user);

              using (new Switcher<Domain, Domain>(new Domain("somedomain")))
              {
            using (new MembershipSwitcher(membershipProvider))
            {
              repository.RegisterUser(registrationInfo.Email,registrationInfo.Password, userProfile);
              membershipProvider.Received(1).CreateUser($@"somedomain\{registrationInfo.Email}", registrationInfo.Password, Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<object>(), out status);
            }
              }
        }
Esempio n. 8
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 GetPasswordHelper(bool requireQA, bool enablePasswordRetrieval, string answer)
        {
            MembershipCreateStatus status;
            provider = new MembershipProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("requiresQuestionAndAnswer", requireQA ? "true" : "false");
            config.Add("enablePasswordRetrieval", enablePasswordRetrieval ? "true" : "false");
            config.Add("passwordFormat", "clear");
            config.Add("applicationName", _applicationName);
            config.Add("writeExceptionsToEventLog", "false");
            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 (MembershipPasswordException)
            {
                if (requireQA && answer != null)
                    Assert.Fail("This should not have thrown an exception");
            }
            catch (ProviderException)
            {
                if (requireQA && answer != null)
                    Assert.Fail("This should not have thrown an exception");
            }
        }
Esempio n. 10
0
        public TransportMembershipUser CreateUser(string applicationName, string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            _Provider.ApplicationName = _ApplicationName;

            return(ConvertUser(_Provider.CreateUser(username, password, email, passwordQuestion, passwordQuestion, isApproved, providerUserKey, out status)));
        }
        public void RegisterShouldCreateLoginUser(FakeMembershipUser user, MembershipProvider membershipProvider, AuthenticationProvider authenticationProvider, RegistrationInfo registrationInfo, AccountRepository repository)
        {
            user.ProviderName.Returns("fake");
              user.UserName.Returns("name");
              MembershipCreateStatus status;
              membershipProvider.CreateUser(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<bool>(), Arg.Any<object>(), out status).Returns(user);
              membershipProvider.GetUser(Arg.Any<string>(), Arg.Any<bool>()).Returns(user);

              using (new Switcher<Domain, Domain>(new Domain("somedomain")))
              {
            using (new MembershipSwitcher(membershipProvider))
            {
              using (new AuthenticationSwitcher(authenticationProvider))
              {
            repository.RegisterUser(registrationInfo);
            authenticationProvider.Received(1).Login(Arg.Is<User>(u => u.Name == $@"somedomain\{registrationInfo.Email}"));
              }
            }
              }
        }
Esempio n. 12
0
        public static string CreateUserAccount(MembershipProvider userMembershipProvider, User user)
        {
            string error = "";

            user.Email = user.Email.ToLower();

            User validateUser = UserService.GetUserByUsername(user.Username);
            if (validateUser.UserID > 0)
                return UserMessages.UsernameAlreadyUsed;

            validateUser = UserService.GetUserByEmail(user.Email);
            if (validateUser.UserID > 0)
                return UserMessages.EmailAlreadyUsed;

            MembershipCreateStatus status;
            MembershipUser mu = userMembershipProvider.CreateUser(user.Email, user.Password, user.Email, null, null, true, null, out status);

            if (status != MembershipCreateStatus.Success)
                return UserMessages.ErrorCreatingAccount;

            user.AspnetUserID = (Guid)mu.ProviderUserKey;

            int userID = CreateUserAccount(user);

            if(userID == 0)
            {
                // Delete user account
                userMembershipProvider.DeleteUser(user.Email, true);
                return UserMessages.ErrorCreatingAccount;
            }

            user.UserID = userID;

            return error;
        }