コード例 #1
0
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion,
            string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if ((RequiresUniqueEmail && (GetUserNameByEmail(email) != String.Empty)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            MembershipUser membershipUser = GetUser(username, false);

            if (membershipUser == null)
            {
                byte[] salt;

                User user = new User();
                user.UserGuid = Guid.NewGuid().ToString();
                user.Username = username;
                user.PasswordHash = accountRepository.GenerateHash(password, out salt);
                user.PasswordSalt = salt;
                user.Email = email;
                user.SignUpDate = DateTime.Now;
                user.LastLoginDate = DateTime.Now;
                user.LastActiveTime = DateTime.Now;

                accountRepository.CreateUser(user);

                status = MembershipCreateStatus.Success;
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
コード例 #2
0
 public void CreateUser(User user)
 {
     usersTable.InsertOnSubmit(user);
     usersTable.Context.SubmitChanges();
 }