Пример #1
0
        }                                                 // Success

        public override void Execute()
        {
            Success = false;

            SafeReader sr = DB.GetFirst(
                "LoadUserDetails",
                CommandSpecies.StoredProcedure,
                new QueryParameter("@UserID", this.userID)
                );

            if (sr.IsEmpty)
            {
                Log.Alert("User not found by id {0}.", this.userID);
                return;
            }             // if

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            HashedPassword hashed = pu.Generate(sr["Email"], Password.Data);

            var sp = new SpUserResetPassword(DB, Log)
            {
                UserID     = this.userID,
                EzPassword = hashed.Password,
                Salt       = hashed.Salt,
                CycleCount = hashed.CycleCount,
            };

            Success = 0 < sp.ExecuteScalar <int>();
        }         // Execute
Пример #2
0
            }             // MatchesEnteredEmail

            public bool IsPasswordValid(string sPassword)
            {
                var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

                if (IsOldPasswordStyle)
                {
                    bool success =
                        (Password == HashPassword(sPassword, Email, CreationDate)) ||
                        (Password == HashPassword(sPassword));

                    if (success)
                    {
                        RenewStoredPassword = pu.Generate(Email, sPassword);
                    }

                    return(success);
                }                 // if

                var storedPassword = new HashedPassword(Email, CycleCount, EzPassword, Salt);

                PasswordValidationResult validateResult = pu.Validate(sPassword, storedPassword);

                RenewStoredPassword = validateResult.NewPassword;

                return(validateResult.Match);
            }             // IsPasswordValid
Пример #3
0
        }         // Name

        public override void Execute()
        {
            bool emptyPassword =
                string.IsNullOrWhiteSpace(this.oldPassword) ||
                string.IsNullOrWhiteSpace(this.newPassword) ||
                string.IsNullOrWhiteSpace(this.newPasswordAgain);

            if (emptyPassword)
            {
                throw new StrategyWarning(this, "Password not specified for broker '" + this.spLoad.ContactEmail + "'.");
            }

            if (this.oldPassword == this.newPassword)
            {
                throw new StrategyWarning(
                          this,
                          "New and old passwords are the same for broker '" + this.spLoad.ContactEmail + "'."
                          );
            }             // if

            if (this.newPassword != this.newPasswordAgain)
            {
                throw new StrategyWarning(
                          this,
                          "New password and its confirmation are not the same for broker '" + this.spLoad.ContactEmail + "'."
                          );
            }             // if

            this.spLoad.ExecuteNonQuery();

            if (BrokerID < 1)
            {
                throw new StrategyWarning(this, "Failed to find broker by email '" + this.spLoad.ContactEmail + "'.");
            }

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            var currentHashed = new HashedPassword(
                this.spLoad.ContactEmail,
                this.spLoad.CycleCount,
                this.spLoad.EzPassword,
                this.spLoad.Salt
                );

            if (!pu.Validate(this.oldPassword, currentHashed))
            {
                throw new StrategyWarning(
                          this,
                          "Current password does not match for broker by email '" + this.spLoad.ContactEmail + "'."
                          );
            }             // if

            var hashed = pu.Generate(this.spLoad.ContactEmail, this.newPassword);

            new SpBrokerUpdatePassword(BrokerID, hashed, DB, Log).ExecuteNonQuery();

            FireToBackground(new BrokerPasswordChanged(BrokerID, this.newPassword));
        }         // Execute
Пример #4
0
            }                                                  // CycleCount

            private void SetPassword()
            {
                var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

                var pass = pu.Generate(ContactEmail, this.rawPassword);

                Password   = pass.Password;
                CycleCount = pass.CycleCount;
                Salt       = pass.Salt;
            }             // SetPassword
Пример #5
0
        }         // Name

        public override void Execute()
        {
            Log.Debug("Resetting password for user {0}...", this.spLoad.TargetID);

            this.spLoad.ExecuteNonQuery();

            if (string.IsNullOrWhiteSpace(this.spLoad.Email))
            {
                Log.Warn("Resetting password for user {0} failed: no email found.", this.spLoad.TargetID);
                return;
            }             // if

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            HashedPassword hashed = pu.Generate(this.spLoad.Email, ThePassword);

            var sp = new SavePassword(this.spLoad, DB, Log)
            {
                Password   = hashed.Password,
                Salt       = hashed.Salt,
                CycleCount = hashed.CycleCount,
            };

            sp.ExecuteNonQuery();

            Log.Debug("Resetting password for user {0} complete.", this.spLoad.TargetID);

            AStrategy oEmailSender = null;

            switch (this.targetType)
            {
            case PasswordResetTarget.Customer:
                oEmailSender = new PasswordChanged(this.spLoad.TargetID, ThePassword);
                break;

            case PasswordResetTarget.Broker:
                oEmailSender = new BrokerPasswordChanged(this.spLoad.TargetID, ThePassword);
                break;
            }             // switch

            FireToBackground(oEmailSender);
        }         // Execute
        public SignupUnderwriterMultiOrigin(string sEmail, DasKennwort sPassword, string sRoleName)
        {
            string userName = NormalizeUserName(sEmail);

            this.securityData = new UserSecurityData(this)
            {
                Email       = userName,
                NewPassword = sPassword.Decrypt(),
            };

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            var pass = pu.Generate(sEmail, this.securityData.NewPassword);

            this.sp = new CreateUserForUnderwriter(DB, Log)
            {
                UserName   = userName,
                EzPassword = pass.Password,
                Salt       = pass.Salt,
                CycleCount = pass.CycleCount,
                RoleName   = (sRoleName ?? string.Empty).Trim().ToLowerInvariant(),
            };
        }         // constructor
Пример #7
0
        public SignupInvestorMultiOrigin(string email)
        {
            string userName = NormalizeUserName(email);

            this.securityData = new UserSecurityData(this)
            {
                Email       = userName,
                NewPassword = "******",
            };

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            var pass = pu.Generate(email, this.securityData.NewPassword);

            this.sp = new CreateUserForInvestor(DB, Log)
            {
                UserName   = userName,
                EzPassword = pass.Password,
                Salt       = pass.Salt,
                CycleCount = pass.CycleCount,
            };

            UserID = 0;
        }         // constructor
Пример #8
0
        }         // Name

        public override void Execute()
        {
            ErrorMessage = null;

            string userDisplay = string.Format("{0} with origin {1}", this.securityData.Email, this.spLoad.OriginID);

            this.securityData.ValidateEmail();
            this.securityData.ValidateOldPassword();
            this.securityData.ValidateNewPassword();

            var oUser = this.spLoad.FillFirst <UserDataForLogin.Result>();

            Log.Debug("User '{0}': data for check is {1}.", userDisplay, oUser);

            if (oUser.Email != this.securityData.Email)
            {
                Log.Debug("User '{0}' not found.", this.securityData.Email);
                ErrorMessage = "Invalid user name.";
                return;
            }             // if

            if (this.securityData.OldPassword == this.securityData.NewPassword)
            {
                Log.Debug("User '{0}': current and new passwords are the same.", userDisplay);
                ErrorMessage = "Current and new passwords are the same.";
                return;
            }             // if

            if (oUser.DisablePassChange.HasValue && oUser.DisablePassChange.Value)
            {
                Log.Debug("User '{0}': changing password is disabled.", userDisplay);
                ErrorMessage = "Changing password is disabled.";
                return;
            }             // if

            if (!oUser.IsPasswordValid(this.securityData.OldPassword))
            {
                Log.Debug("User '{0}': current password does not match.", userDisplay);
                ErrorMessage = "Current password does not match.";
                return;
            }             // if

            UserID = oUser.UserID;

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            var hashed = pu.Generate(oUser.Email, this.securityData.NewPassword);

            this.spResult.UserID     = oUser.UserID;
            this.spResult.EzPassword = hashed.Password;
            this.spResult.Salt       = hashed.Salt;
            this.spResult.CycleCount = hashed.CycleCount;

            ErrorMessage = this.spResult.ExecuteScalar <string>();

            Log.Debug(
                "User '{0}' password has{1} been changed. {2}",
                userDisplay,
                string.IsNullOrWhiteSpace(ErrorMessage) ? "" : " NOT",
                ErrorMessage
                );

            if (string.IsNullOrWhiteSpace(ErrorMessage))
            {
                FireToBackground(new PasswordChanged(UserID, RawPassword));
            }
        }         // Execute
        }         // GenerateConfirmationToken

        private void CreateSecurityUserStuff()
        {
            if (this.model.Origin == null)
            {
                SetInternalErrorMsg();
                Log.Alert("Sign up attempt {0}: no origin specified.", this.uniqueID);
                throw new BadDataException();
            }             // if

            if (this.model.PasswordQuestion == null)
            {
                SetInternalErrorMsg();
                Log.Alert("Sign up attempt {0}: no security question specified.", this.uniqueID);
                throw new BadDataException();
            }             // if

            try {
                string rawPassword = this.model.RawPassword.Decrypt();

                var data = new UserSecurityData(this)
                {
                    Email            = this.model.UserName,
                    NewPassword      = rawPassword,
                    PasswordQuestion = this.model.PasswordQuestion.Value,
                    PasswordAnswer   = this.model.PasswordAnswer,
                };

                Log.Debug("Sign up attempt '{0}': validating user name...", this.uniqueID);

                data.ValidateEmail();

                Log.Debug("Sign up attempt '{0}': validating password...", this.uniqueID);

                data.ValidateNewPassword();

                Log.Debug("Sign up attempt '{0}': validated user name and password.", this.uniqueID);

                var passUtil = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

                HashedPassword hashedPassword = passUtil.Generate(this.model.UserName, rawPassword);

                var sp = new CreateUserForCustomer(DB, Log)
                {
                    OriginID           = (int)this.model.Origin.Value,
                    Email              = this.model.UserName,
                    EzPassword         = hashedPassword.Password,
                    Salt               = hashedPassword.Salt,
                    CycleCount         = hashedPassword.CycleCount,
                    SecurityQuestionID = this.model.PasswordQuestion,
                    SecurityAnswer     = this.model.PasswordAnswer,
                    Ip = this.model.RemoteIp,
                };

                UserID = 0;

                sp.ForEachRowSafe(this.dbTransaction, (sr, bRowsetStart) => {
                    if (!sr.ContainsField("UserID"))
                    {
                        return(ActionResult.Continue);
                    }

                    UserID    = sr["UserID"];
                    SessionID = sr["SessionID"];
                    return(ActionResult.SkipAll);
                });

                Status = MembershipCreateStatus.ProviderError;

                switch (UserID)
                {
                case (int)CreateUserForCustomer.Errors.DuplicateUser:
                    ErrorMsg =
                        "This email address already exists in our system. " +
                        "Please try to log-in or request new password.";

                    Status = MembershipCreateStatus.DuplicateEmail;

                    Log.Warn(
                        "Sign up attempt '{0}': user with email {1} and origin {2} already exists.",
                        this.uniqueID,
                        this.model.UserName,
                        this.model.Origin.Value
                        );

                    break;

                case (int)CreateUserForCustomer.Errors.OriginNotFound:
                    Log.Alert("Sign up attempt '{0}': origin {1} was not found.", this.uniqueID, this.model.Origin.Value);
                    SetInternalErrorMsg();
                    break;

                case (int)CreateUserForCustomer.Errors.RoleNotFound:
                case (int)CreateUserForCustomer.Errors.FailedToCreateUser:
                case (int)CreateUserForCustomer.Errors.FailedToAttachRole:
                case (int)CreateUserForCustomer.Errors.FailedToCreateSession:
                case (int)CreateUserForCustomer.Errors.ConflictsWithInternal:
                case (int)CreateUserForCustomer.Errors.ConflictsWithBroker:
                    Log.Alert(
                        "Sign up attempt '{0}' - internal DB error: {1}.",
                        this.uniqueID,
                        ((CreateUserForCustomer.Errors)UserID).DescriptionAttr()
                        );
                    SetInternalErrorMsg();
                    break;

                default:
                    if (UserID <= 0)
                    {
                        Log.Alert(
                            "Sign up attempt '{0}': {1} returned unexpected result: {2}.",
                            this.uniqueID,
                            sp.GetType().Name,
                            UserID
                            );
                        SetInternalErrorMsg();
                    }
                    else
                    {
                        Log.Msg(
                            "Sign up attempt '{0}': user '{1}' with origin {2} was inserted into Security_User table.",
                            this.uniqueID,
                            this.model.UserName,
                            this.model.Origin.Value
                            );
                        Status = MembershipCreateStatus.Success;
                    }                     // if

                    break;
                }                 // switch
            } catch (AException ae) {
                SetInternalErrorMsg();
                Log.Alert("Sign up attempt {0} threw an exception: {1}.", this.uniqueID, ae.Message);
                throw new InternalErrorException();
            } catch (Exception e) {
                SetInternalErrorMsg();
                Log.Alert(e, "Sign up attempt {0} threw an exception.", this.uniqueID);
                throw new InternalErrorException();
            }     // try
        }         // CreateSecurityUserStuff
Пример #10
0
        public JsonResult CustomerCreatePassword(CreatePasswordModel model)
        {
            var customerIp = RemoteIp();

            if (!ModelState.IsValid)
            {
                log.Debug(
                    "Customer create password attempt from remote IP {0}: model state is invalid, list of errors:",
                    customerIp
                    );

                foreach (var val in ModelState.Values)
                {
                    if (val.Errors.Count < 1)
                    {
                        continue;
                    }

                    foreach (var err in val.Errors)
                    {
                        log.Debug("Model value '{0}' with error '{1}'.", val.Value, err.ErrorMessage);
                    }
                }                 // for each value

                log.Debug("End of list of errors.");

                return(Json(new {
                    success = false,
                    errorMessage = "Failed to set a password.",
                }, JsonRequestBehavior.AllowGet));
            }             // if

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            log.Debug(
                "Customer create password attempt from remote IP {0} received: {1}...",
                customerIp,
                pu.Generate(model.UserName, model.Password)
                );

            CustomerOriginEnum      origin = UiCustomerOrigin.Get().GetOrigin();
            SetPasswordActionResult spar;

            try {
                spar = this.serviceClient.Instance.SetCustomerPasswordByToken(
                    model.Token,
                    origin,
                    new DasKennwort(model.Password),
                    new DasKennwort(model.signupPass2),
                    model.IsBrokerLead,
                    customerIp
                    );
            } catch (Exception e) {
                log.Warn(e, "Failed to set new password for user '{0}'.", model.UserName);

                return(Json(new {
                    success = false,
                    errorMessage = "Failed to set a password.",
                }, JsonRequestBehavior.AllowGet));
            }             // try

            if (!string.IsNullOrWhiteSpace(spar.ErrorMsg))
            {
                log.Warn(
                    "Failed to set a password for user name {0}, error message returned: {1}.",
                    model.UserName,
                    spar.ErrorMsg
                    );

                return(Json(new {
                    success = false,
                    errorMessage = spar.ErrorMsg,
                }, JsonRequestBehavior.AllowGet));
            }             // if

            if (spar.UserID <= 0)
            {
                log.Warn("Failed to set a password (returned user id is 0) for user name {0}.", model.UserName);

                return(Json(new {
                    success = false,
                    errorMessage = "Failed to set a password.",
                }, JsonRequestBehavior.AllowGet));
            }             // if

            if (spar.IsBroker)
            {
                BrokerHelper.SetAuth(spar.Email);

                return(Json(new {
                    success = true,
                    errorMessage = string.Empty,
                    broker = true,
                }));
            }             // if is broker

            if (spar.SessionID != 0)
            {
                Session["UserSessionId"] = spar.SessionID;
            }

            if (string.IsNullOrWhiteSpace(spar.ErrorMsg))
            {
                model.SetCookie(LogOnModel.Roles.Customer);
                this.context.SetSessionOrigin(origin);
            }             // if

            return(Json(new {
                success = string.IsNullOrWhiteSpace(spar.ErrorMsg),
                errorMessage = spar.ErrorMsg,
                broker = false,
            }, JsonRequestBehavior.AllowGet));
        }         // CustomerCreatePassword
Пример #11
0
        public JsonResult CustomerLogOn(LogOnModel model)
        {
            string             customerIp = RemoteIp();
            CustomerOriginEnum origin     = UiCustomerOrigin.Get().GetOrigin();

            if (!ModelState.IsValid)
            {
                log.Debug(
                    "Customer log on attempt from remote IP {0} to origin '{1}': model state is invalid, list of errors:",
                    customerIp,
                    origin
                    );

                foreach (var val in ModelState.Values)
                {
                    if (val.Errors.Count < 1)
                    {
                        continue;
                    }

                    foreach (var err in val.Errors)
                    {
                        log.Debug("Model value '{0}' with error '{1}'.", val.Value, err.ErrorMessage);
                    }
                }                 // for each value

                log.Debug("End of list of errors.");

                return(Json(new {
                    success = false,
                    errorMessage = "User not found or incorrect password."
                }, JsonRequestBehavior.AllowGet));
            }             // if

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            log.Debug(
                "Customer log on attempt from remote IP {0} received " +
                "with user name '{1}' and hash '{2}' (promotion: {3})...",
                customerIp,
                model.UserName,
                pu.Generate(model.UserName, model.Password),
                model.PromotionDisplayData
                );

            try {
                if (this.brokerHelper.IsBroker(model.UserName))
                {
                    BrokerProperties bp = this.brokerHelper.TryLogin(
                        model.UserName,
                        model.Password,
                        model.PromotionName,
                        model.PromotionPageVisitTime
                        );

                    if ((bp != null) && (bp.CurrentTermsID != bp.SignedTermsID))
                    {
                        Session[Constant.Broker.Terms]   = bp.CurrentTerms;
                        Session[Constant.Broker.TermsID] = bp.CurrentTermsID;
                    }                     // if

                    return(Json(new {
                        success = (bp != null),
                        errorMessage = (bp == null) ? "User not found or incorrect password." : string.Empty,
                        broker = true,
                    }));
                }                 // if is broker
            } catch (Exception e) {
                log.Warn(
                    e,
                    "Failed to check whether '{0}' is a broker login at origin '{1}', continuing as a customer.",
                    model.UserName,
                    origin
                    );
            }             // try

            var loginModel = new LoginCustomerMultiOriginModel {
                UserName               = model.UserName,
                Origin                 = origin,
                Password               = new DasKennwort(model.Password),
                PromotionName          = model.PromotionName,
                PromotionPageVisitTime = model.PromotionPageVisitTime,
                RemoteIp               = customerIp,
            };

            UserLoginActionResult ular = this.serviceClient.Instance.LoginCustomerMutliOrigin(loginModel);

            if (MembershipCreateStatus.Success.ToString() == ular.Status)
            {
                model.SetCookie(LogOnModel.Roles.Customer);
                this.context.SetSessionOrigin(origin);
                return(Json(new { success = true, model, }, JsonRequestBehavior.AllowGet));
            }             // if

            // If we got this far, something failed, redisplay form
            return(Json(new { success = false, errorMessage = ular.ErrorMessage }, JsonRequestBehavior.AllowGet));
        }         // CustomerLogOn
Пример #12
0
        }         // Name

        public override void Execute()
        {
            this.spDetails.Load();

            if (this.spDetails.Data.UserID <= 0)
            {
                Log.Warn("Failed to find user by token {0}.", this.spDetails.Token);
                ErrorMsg = "Invalid password restore token.";
                return;
            }             // if

            if ((this.spDetails.Data.OriginID == null) || (this.spDetails.Data.OriginID <= 0))
            {
                Log.Warn(
                    "User {1} (found by token {0}) has no proper origin set.",
                    this.spDetails.Token,
                    this.spDetails.Data.UserID
                    );
                ErrorMsg = "Invalid password restore token.";
                return;
            }             // if

            if ((int)this.origin != this.spDetails.Data.OriginID)
            {
                Log.Warn(
                    "User {1} (found by token {0}) has origin '{2}' while source UI origin is '{3}'.",
                    this.spDetails.Token,
                    this.spDetails.Data.UserID,
                    this.spDetails.Data.OriginID,
                    (int)this.origin
                    );
                ErrorMsg = "Invalid password restore token.";
                return;
            }             // if

            if (!ValidatePassword())
            {
                return;
            }

            this.spSetNewPassword.UserID = this.spDetails.Data.UserID;
            UserID = this.spDetails.Data.UserID;

            var pu = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

            HashedPassword hashed = pu.Generate(this.spDetails.Data.Email, this.securityData.NewPassword);

            this.spSetNewPassword.EzPassword = hashed.Password;
            this.spSetNewPassword.Salt       = hashed.Salt;
            this.spSetNewPassword.CycleCount = hashed.CycleCount;

            SafeReader sr = this.spSetNewPassword.GetFirst();

            if (sr.IsEmpty)
            {
                ErrorMsg = "Failed to set new password.";
                return;
            }             // if

            IsBroker   = sr["IsBroker"];
            SessionID  = sr["SessionID"];
            IsDisabled = sr["IsDisabled"];

            if (IsDisabled)
            {
                ErrorMsg = string.Format(
                    "This account is closed, please contact <span class='bold'>{0}</span> customer care<br/> {1}",
                    sr["OriginName"],
                    sr["CustomerCareEmail"]
                    );
            }     // if
        }         // Execute