コード例 #1
0
    /// <summary>
    /// Handling login authenticate event.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">Authenticate event arguments.</param>
    private void loginElem_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (MFAuthenticationHelper.IsMultiFactorRequiredForUser(loginElem.UserName))
        {
            var plcPasscodeBox = loginElem.FindControl("plcPasscodeBox");
            var plcLoginInputs = loginElem.FindControl("plcLoginInputs");
            var txtPasscode    = loginElem.FindControl("txtPasscode") as CMSTextBox;

            if (txtPasscode == null)
            {
                return;
            }
            if (plcPasscodeBox == null)
            {
                return;
            }
            if (plcLoginInputs == null)
            {
                return;
            }

            // Handle passcode
            string passcode = txtPasscode.Text;
            txtPasscode.Text = "";

            var provider = new CMSMembershipProvider();

            // Validate username and password
            if (plcLoginInputs.Visible)
            {
                if (provider.MFValidateCredentials(loginElem.UserName, loginElem.Password))
                {
                    // Show passcode screen
                    plcLoginInputs.Visible = false;
                    plcPasscodeBox.Visible = true;
                }
            }
            // Validate passcode
            else
            {
                if (provider.MFValidatePasscode(loginElem.UserName, passcode))
                {
                    e.Authenticated = true;
                }
            }
        }
        else
        {
            try
            {
                e.Authenticated = Membership.Provider.ValidateUser(loginElem.UserName, loginElem.Password);
            }
            catch (ConfigurationException ex)
            {
                EventLogProvider.LogException("LogonMiniForm", "VALIDATEUSER", ex);
                var provider = new CMSMembershipProvider();
                e.Authenticated = provider.ValidateUser(loginElem.UserName, loginElem.Password);
            }
        }
    }
コード例 #2
0
ファイル: LogonForm.ascx.cs プロジェクト: isatriya/kentico10
    /// <summary>
    /// Handling login authenticate event.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">Authenticate event arguments.</param>
    private void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (MFAuthenticationHelper.IsMultiFactorRequiredForUser(Login1.UserName))
        {
            var plcPasscodeBox = Login1.FindControl("plcPasscodeBox");
            var plcLoginInputs = Login1.FindControl("plcLoginInputs");
            var txtPasscode    = Login1.FindControl("txtPasscode") as CMSTextBox;

            if (txtPasscode == null)
            {
                return;
            }
            if (plcPasscodeBox == null)
            {
                return;
            }
            if (plcLoginInputs == null)
            {
                return;
            }

            // Handle passcode
            string passcode = txtPasscode.Text;
            txtPasscode.Text = string.Empty;

            var provider = new CMSMembershipProvider();

            // Validate username and password
            if (plcLoginInputs.Visible)
            {
                if (provider.MFValidateCredentials(Login1.UserName, Login1.Password))
                {
                    // Show passcode screen
                    plcLoginInputs.Visible = false;
                    plcPasscodeBox.Visible = true;
                }
            }
            // Validate passcode
            else
            {
                if (provider.MFValidatePasscode(Login1.UserName, passcode))
                {
                    e.Authenticated = true;
                }
            }
        }
        else
        {
            e.Authenticated = Membership.Provider.ValidateUser(Login1.UserName, Login1.Password);
        }
    }
コード例 #3
0
    /// <summary>
    /// Prepares the callback result.
    /// </summary>
    public string GetCallbackResult()
    {
        var user = MembershipContext.AuthenticatedUser;

        if (!user.Enabled)
        {
            return("accountLocked");
        }

        if (userValidates)
        {
            if (RequestHelper.IsWindowsAuthentication())
            {
                return(UnlockScreen());
            }

            // User wants to revalidate his session
            if (UserInfoProvider.IsUserPasswordDifferent(user, validatePassword))
            {
                // Password is invalid
                AuthenticationHelper.CheckInvalidPasswordAttempts(user, SiteContext.CurrentSiteName);

                if (!user.Enabled)
                {
                    return("accountLocked");
                }
                return("valbad");
            }

            if (userWaitingForPasscode)
            {
                return(GeneratePasscode(user));
            }

            // Password is correct
            return(UnlockScreen());
        }

        if (passcValidates)
        {
            var membershipProvider = new CMSMembershipProvider();
            if (membershipProvider.MFValidatePasscode(user, validatePasscode, false))
            {
                return(UnlockScreen());
            }

            if (!user.Enabled)
            {
                return("accountLocked");
            }
            return("wrongPassc|" + GetString("mfauthentication.passcode.wrong"));
        }

        if (CMSPage.IsScreenLocked)
        {
            if (userAsksForState)
            {
                // Screen is locked
                return("isLocked|True");
            }

            if (!userIsLoggingOut)
            {
                return("");
            }

            // User wants to logout
            string signOutUrl = SystemContext.ApplicationPath.TrimEnd('/') + "/default.aspx";

            if (IsCMSDesk)
            {
                // LiveID sign out URL is set if this LiveID session
                AuthenticationHelper.SignOut(ref signOutUrl);
            }
            else
            {
                AuthenticationHelper.SignOut();
            }

            return("logout|" + signOutUrl);
        }

        // Check if ScreenLock is active
        if (!SecurityHelper.IsScreenLockEnabled(SiteContext.CurrentSiteName))
        {
            return("disabled");
        }

        // User is canceling countdown and wants to stay active
        if (userCanceling)
        {
            SecurityHelper.LogScreenLockAction();
            return("cancelOk|" + SecurityHelper.GetSecondsToShowScreenLockAction(SiteContext.CurrentSiteName));
        }

        if ((int)timeLeft.TotalSeconds <= 0)
        {
            // User was inactive too long - lock screen
            CMSPage.IsScreenLocked = true;
            return("lockScreen");
        }

        if ((int)timeLeft.TotalSeconds <= secondsToWarning)
        {
            // Lock screen timeout is close - display warning
            return("showWarning|" + ((int)timeLeft.TotalSeconds).ToString());
        }

        // User is active - hide warning and lock screen (if opened)
        return("hideWarning|" + ((int)timeLeft.TotalSeconds - secondsToWarning).ToString());
    }
    /// <summary>
    /// Handling login authenticate event.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">Authenticate event arguments.</param>
    private void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (MFAuthenticationHelper.IsMultiFactorRequiredForUser(Login1.UserName))
        {
            var plcPasscodeBox = Login1.FindControl("plcPasscodeBox");
            var plcLoginInputs = Login1.FindControl("plcLoginInputs");
            var txtPasscode = Login1.FindControl("txtPasscode") as CMSTextBox;

            if (txtPasscode == null)
            {
                return;
            }
            if (plcPasscodeBox == null)
            {
                return;
            }
            if (plcLoginInputs == null)
            {
                return;
            }

            // Handle passcode
            string passcode = txtPasscode.Text;
            txtPasscode.Text = string.Empty;

            var provider = new CMSMembershipProvider();

            // Validate username and password
            if (plcLoginInputs.Visible)
            {
                if (provider.MFValidateCredentials(Login1.UserName, Login1.Password))
                {
                    // Show passcode screen
                    plcLoginInputs.Visible = false;
                    plcPasscodeBox.Visible = true;
                }
            }
            // Validate passcode
            else
            {
                if (provider.MFValidatePasscode(Login1.UserName, passcode))
                {
                    e.Authenticated = true;
                }
            }
        }
        else
        {
            e.Authenticated = Membership.Provider.ValidateUser(Login1.UserName, Login1.Password);
        }
    }
コード例 #5
0
    /// <summary>
    /// Prepares the callback result.
    /// </summary>
    public string GetCallbackResult()
    {
        var user = MembershipContext.AuthenticatedUser;

        if (!user.Enabled)
        {
            return "accountLocked";
        }

        if (userValidates)
        {
            if (RequestHelper.IsWindowsAuthentication())
            {
                return UnlockScreen();
            }

            // User wants to revalidate his session
            if (UserInfoProvider.IsUserPasswordDifferent(user, validatePassword))
            {
                // Password is invalid
                AuthenticationHelper.CheckInvalidPasswordAttempts(user, SiteContext.CurrentSiteName);

                if (!user.Enabled)
                {
                    return "accountLocked";
                }
                return "valbad";
            }

            if (userWaitingForPasscode)
            {
                return GeneratePasscode(user);
            }

            // Password is correct
            return UnlockScreen();
        }

        if (passcValidates)
        {
            var membershipProvider = new CMSMembershipProvider();
            if (membershipProvider.MFValidatePasscode(user, validatePasscode, false))
            {
                return UnlockScreen();
            }

            if (!user.Enabled)
            {
                return "accountLocked";
            }
            return "wrongPassc|" + GetString("mfauthentication.passcode.wrong");
        }

        if (CMSPage.IsScreenLocked)
        {
            if (userAsksForState)
            {
                // Screen is locked
                return "isLocked|True";
            }

            if (!userIsLoggingOut)
            {
                return "";
            }

            // User wants to logout
            string signOutUrl = SystemContext.ApplicationPath.TrimEnd('/') + "/default.aspx";

            if (IsCMSDesk)
            {
                // LiveID sign out URL is set if this LiveID session
                AuthenticationHelper.SignOut(ref signOutUrl);
            }
            else
            {
                AuthenticationHelper.SignOut();
            }

            return "logout|" + signOutUrl;
        }

        // Check if ScreenLock is active
        if (!SecurityHelper.IsScreenLockEnabled(SiteContext.CurrentSiteName))
        {
            return "disabled";
        }

        // User is canceling countdown and wants to stay active
        if (userCanceling)
        {
            SecurityHelper.LogScreenLockAction();
            return "cancelOk|" + SecurityHelper.GetSecondsToShowScreenLockAction(SiteContext.CurrentSiteName);
        }

        if ((int)timeLeft.TotalSeconds <= 0)
        {
            // User was inactive too long - lock screen
            CMSPage.IsScreenLocked = true;
            return "lockScreen";
        }

        if ((int)timeLeft.TotalSeconds <= secondsToWarning)
        {
            // Lock screen timeout is close - display warning
            return "showWarning|" + ((int)timeLeft.TotalSeconds).ToString();
        }

        // User is active - hide warning and lock screen (if opened)
        return "hideWarning|" + ((int)timeLeft.TotalSeconds - secondsToWarning).ToString();
    }