public CredentialsManager(string pi_propertyname, string pi_contractnumber, string pi_install, int pi_propertyid)
        {
            m_Encryptor = KeyValidate.getKeyValidator("TR_TP", pi_propertyname, pi_contractnumber, pi_install);

            if (m_Encryptor == null)
            {
                throw(new Exception("Either the Install Key, Property Name, or Contract Number is wrong..."));
            }
            else
            {
                m_IniFileName = m_Utils.AppPath + "ENC_FILE.ini";
                this.loadProps();
                UserSecurityInfo info = this.getServiceConnectionInfo();
                this.m_TPUserID   = info.LogName;
                this.m_TPPassword = info.Password;
            }
        }
Beispiel #2
0
        public void SetPassword(string account, string password)
        {
            if (string.IsNullOrWhiteSpace(account) ||
                string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("设置密码时发生参数错误");
            }
            UserSecurityInfo securityInfo = UserSecurityInfoRepo
                                            .Read()
                                            .FirstOrDefault(us => us.Account.ToLower() == account.ToLower());

            if (securityInfo == null)
            {
                securityInfo    = new UserSecurityInfo();
                securityInfo.Id = StringFactory.NewGuid();
            }
            securityInfo.Account  = account;
            securityInfo.Password = StringFactory.HashBySolt(password);
            UserSecurityInfoRepo.Save(securityInfo);
        }
 /// <summary>
 /// Validates the user internal.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="password">The password.</param>
 /// <returns></returns>
 bool ValidateUserInternal(UserSecurityInfo user, string password)
 {
     if (user != null) {
         string pass = TransformPassword (password, ref user.PasswordSalt);
         if (string.Equals (pass, user.Password, StringComparison.OrdinalIgnoreCase)) {
             return true;
         }
     }
     return false;
 }
        /// <summary>
        /// Adds a new membership user to the data source.
        /// </summary>
        /// <param name="username">The user name for the new user.</param>
        /// <param name="password">The password for the new user.</param>
        /// <param name="email">The e-mail address for the new user.</param>
        /// <param name="passwordQuestion">The password question for the new user.</param>
        /// <param name="passwordAnswer">The password answer for the new user</param>
        /// <param name="isApproved">Whether or not the new user is approved to be validated.</param>
        /// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param>
        /// <param name="status">A <see cref="T:System.Web.Security.MembershipCreateStatus"></see> enumeration value indicating whether the user was created successfully.</param>
        /// <returns>
        /// A <see cref="T:System.Web.Security.MembershipUser"></see> object populated with the information for the newly created user.
        /// </returns>
        public override MembershipUser CreateUser(string username, string password, string email,
                        string passwordQuestion, string passwordAnswer, bool isApproved,
                        Guid providerUserKey, out MembershipCreateStatus status)
        {
            try {
                using (var session = DocumentStore.OpenSession()) {

                    bool isUserNameOk = true;
                    bool isEmailOk = true;

                    ValidateUserNameAndEmail (username, email, ref isUserNameOk, ref isEmailOk, Guid.Empty);

                    // Validate the username
                    if (!isUserNameOk) {
                        status = MembershipCreateStatus.InvalidUserName;
                        return null;
                    }

                    // Validate the email
                    if (!isEmailOk) {
                        status = MembershipCreateStatus.InvalidEmail;
                        return null;
                    }

                    // Raise the event before validating the password
                    OnValidatingPassword (
                                    new ValidatePasswordEventArgs (
                                            username, password, true)
                    );

                    // Validate the password
                    if (!ValidatePassword (password)) {
                        status = MembershipCreateStatus.InvalidPassword;
                        return null;
                    }

                    // Everything is valid, create the user
                    var user = new MembershipUser (username,
                                                providerUserKey, email, passwordQuestion,
                                                "", isApproved, false, DateTime.Today,
                                                DateTime.MinValue, DateTime.MinValue,
                                                DateTime.MinValue, DateTime.MinValue);
                    var secInfo = new UserSecurityInfo ();
                    var salt = "";
                    secInfo.Password = TransformPassword (password, ref salt);
                    secInfo.PasswordSalt = salt;
                    secInfo.PasswordAnswer = passwordAnswer;
                    secInfo.PasswordVerificationToken = new Guid ().ToString ();
                    secInfo.UserName = username;
                    session.Store (user);
                    session.Store (secInfo);

                    status = MembershipCreateStatus.Success;
                    return CreateMembershipFromInternalUser (user);
                }

            } catch {
                throw;
            }
        }
        /// <summary>
        /// Creates the account.
        /// </summary>
        /// <returns>
        /// A token that can be sent to the user to confirm the user account.
        /// </returns>
        /// <param name='userName'>
        /// The user name.
        /// </param>
        /// <param name='password'>
        /// The password.
        /// </param>
        /// <param name='requireConfirmationToken'>
        /// (Optional) true to specify that the user account must be confirmed; otherwise, false. The default is false.
        /// </param>
        public override string CreateAccount(string userName, string password, bool requireConfirmationToken = false)
        {
            try {
                using (var session = DocumentStore.OpenSession()) {
                    bool isUserNameOk = true;
                    bool isEmailOk = true;

                    ValidateUserNameAndEmail (userName, "", ref isUserNameOk, ref isEmailOk, Guid.Empty);

                    // Validate the username
                    if (!isUserNameOk) {
                        throw new MembershipException (string.Format ("The username {0} already exists.", userName));
                    }

                    // Validate the password
                    if (!ValidatePassword (password)) {
                        throw new MembershipException ("The password is not valid.");
                    }

                    // Everything is valid, create the user
                    var user = new MembershipUser (userName,
                                                Guid.NewGuid (), "", "",
                                                "", true, false, DateTime.Today,
                                                DateTime.MinValue, DateTime.MinValue,
                                                DateTime.MinValue, DateTime.MinValue);
                    var secInfo = new UserSecurityInfo ();
                    var salt = "";
                    secInfo.Password = TransformPassword (password, ref salt);
                    secInfo.PasswordSalt = salt;
                    secInfo.PasswordAnswer = "";
                    secInfo.PasswordVerificationToken = requireConfirmationToken == false ? "" : Guid.NewGuid ().ToString ();
                    secInfo.UserName = userName;
                    session.Store (user);
                    session.Store (secInfo);
                    return secInfo.PasswordVerificationToken;
                }

            } catch {
                throw;
            }
        }