Ejemplo n.º 1
0
        /// <summary>
        /// WindowsAuthorization checks whether the user credentials are valid
        /// Windows credentials
        /// </summary>
        /// <param name="loginStatus">The log in status</param>
        /// <history>
        ///     [cnurse]	03/15/2006
        /// </history>
        private UserInfo WindowsAuthorization(UserLoginStatus loginStatus)
        {
            string strMessage = Null.NullString;

            UserInfo objUser = UserController.GetUserByName(PortalSettings.PortalId, txtUsername.Text, false);
            AuthenticationController objAuthentication = new AuthenticationController();

            DotNetNuke.Security.Authentication.UserInfo objAuthUser = objAuthentication.ProcessFormAuthentication(txtUsername.Text, txtPassword.Text);
            int _userID = -1;

            if ((objAuthUser != null) && (objUser == null))
            {
                // Add this user into DNN database for better performance on next logon
                UserCreateStatus createStatus;
                DotNetNuke.Security.Authentication.UserController objAuthUsers = new DotNetNuke.Security.Authentication.UserController();
                createStatus = objAuthUsers.AddDNNUser(objAuthUser);
                _userID      = objAuthUser.UserID;

                // Windows/DNN password validation should be same, check this status here
                strMessage = UserController.GetUserCreateStatus(createStatus);
            }
            else if ((objAuthUser != null) && (objUser != null))
            {
                // User might has been imported by Admin or automatically added with random password
                // update DNN password to match with authenticated password from AD
                if (objUser.Membership.Password != txtPassword.Text)
                {
                    UserController.ChangePassword(objUser, objUser.Membership.Password, txtPassword.Text);
                }
                _userID = objUser.UserID;
            }

            if (_userID > 0)
            {
                // Authenticated with DNN
                objUser = UserController.ValidateUser(PortalId, txtUsername.Text, txtPassword.Text, "", PortalSettings.PortalName, ipAddress, ref loginStatus);
                if (loginStatus != UserLoginStatus.LOGIN_SUCCESS)
                {
                    strMessage = Localization.GetString("LoginFailed", this.LocalResourceFile);
                }
            }
            else
            {
                objUser = null;
            }

            AddLocalizedModuleMessage(strMessage, ModuleMessageType.RedError, !String.IsNullOrEmpty(strMessage));

            return(objUser);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// WindowsAuthorization checks whether the user credentials are valid
        /// Windows credentials
        /// </summary>
        /// <param name="loginStatus">The log in status</param>
        /// <history>
        /// 	[cnurse]	03/15/2006
        /// </history>
        private UserInfo WindowsAuthorization( UserLoginStatus loginStatus )
        {
            string strMessage = Null.NullString;

            UserInfo objUser = UserController.GetUserByName( PortalSettings.PortalId, txtUsername.Text, false );
            AuthenticationController objAuthentication = new AuthenticationController();
            DotNetNuke.Security.Authentication.UserInfo objAuthUser = objAuthentication.ProcessFormAuthentication(txtUsername.Text, txtPassword.Text);
            int _userID = - 1;

            if( ( objAuthUser != null ) && ( objUser == null ) )
            {
                // Add this user into DNN database for better performance on next logon
                UserCreateStatus createStatus;
                DotNetNuke.Security.Authentication.UserController objAuthUsers = new DotNetNuke.Security.Authentication.UserController();
                createStatus = objAuthUsers.AddDNNUser( objAuthUser );
                _userID = objAuthUser.UserID;

                // Windows/DNN password validation should be same, check this status here
                strMessage = UserController.GetUserCreateStatus( createStatus );
            }
            else if( ( objAuthUser != null ) && ( objUser != null ) )
            {
                // User might has been imported by Admin or automatically added with random password
                // update DNN password to match with authenticated password from AD
                if( objUser.Membership.Password != txtPassword.Text )
                {
                    UserController.ChangePassword( objUser, objUser.Membership.Password, txtPassword.Text );
                }
                _userID = objUser.UserID;
            }

            if( _userID > 0 )
            {
                // Authenticated with DNN
                objUser = UserController.ValidateUser( PortalId, txtUsername.Text, txtPassword.Text, "", PortalSettings.PortalName, ipAddress, ref loginStatus );
                if( loginStatus != UserLoginStatus.LOGIN_SUCCESS )
                {
                    strMessage = Localization.GetString( "LoginFailed", this.LocalResourceFile );
                }
            }
            else
            {
                objUser = null;
            }

            AddLocalizedModuleMessage( strMessage, ModuleMessageType.RedError, !String.IsNullOrEmpty(strMessage) );

            return objUser;
        }