0

私がやりたいのは、最大ログイン試行が試行されたかどうかを確認するためにチェックする必要があるコードのセクションをどこに配置する必要があるかを理解することです。その後、10分が経過したかどうかを確認しますが、そうすればユーザーはもう一度ログインしてみてください。このロジックをどのように追加すべきかわからない。

function submit()
{
    // Sets validation rules for the login form
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
    $this->form_validation->set_rules('remember', 'Remember me', 'integer');

    // Checks to see if login form was submitted properly
    if ($this->form_validation->run() === false)
    {
        $outputArray = array('error' => 'yes', 'message' => 'There was a problem submitting the form! Please refresh the window and try again!');  
    }
    else
    {
        if (is_null($userData = $this->usersmodel->getUserByUsername($this->input->post('username'))))
        {
            // Username was not found in the database
            $outputArray = array('error' => 'yes', 'message' => 'Incorrect username and password combination!');  
        }
        else
        {
            // Checks to see if user has exceeded max login attempts
            if ($this->auth->isMaxLoginAttemptsExceeded($userData->userID))
            {

                // Max was exceeded and sends email to account holder
                $outputArray = array('error' => 'yes', 'message' => 'Your account is currently locked, we appologize for the inconvienence. You must wait 10 minutes before you can login again! An email was sent to the owner of this account!');  
                $userData = array('userID' => $userData->userID, 'firstName' => $userData->firstName, 'lastName' => $userData->lastName, 'email' => $userData->email, 'username' => $userData->username);
                $this->auth->sendEmail($this->config->item('defaultTemplate'), 'maxlogins', 'KOW Manager Account Locked', $userData);  
            }
            else
            {
                // Matches user's status for validity
                switch($userData->usersStatusesID)
                {
                    // Registered not validated
                    case 1:
                        $outputArray = array('error' => 'yes', 'message' => 'Sorry you must verify your account before logging in!');  
                        break;
                    // Account suspended
                    case 3:  
                        $outputArray = array('error' => 'yes', 'message' => 'Your account has been suspended!');  
                        break;
                    // Account Banned
                    case 4:
                        $outputArray = array('error' => 'yes', 'message' => 'Your account is currently banned!');  
                        break;
                    // Account Deleted
                    case 5:  
                        $outputArray = array('error' => 'yes', 'message' => 'Your account has been deleted!');  
                        break;
                    // Registered and validated
                    default:
                        // Checks to see if login was successful
                        if ($this->auth->login($this->input->post('username'), $this->input->post('password'), $this->input->post('remember')))
                        {
                            // Login was successful
                            $outputArray = array('success' => 'Yes', 'message' => 'Sending to control panel!');    
                        }
                        else
                        {
                            // Login failed
                            $outputArray = array('error' => 'yes', 'message' => 'Incorrect username and password combination!');  
                        } 
                }
            }

        }
    }
    echo json_encode($outputArray);      
}

/**
* Check if login attempts exceeded max login attempts
*
* @param       integer
* @return      bool
*/
function isMaxLoginAttemptsExceeded($userID)
{
    $this->ci->load->model('users/usersmodel');
    $loginAttempts = $this->ci->usersmodel->getLoginAttemptsNum($this->ci->input->ip_address(), $userID);
    if ($loginAttempts >= 5)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**
 * Get number of attempts to login occured from given IP-address or username
 *
 * @param   string
 * @param   string
 * @return  integer
 */
function getLoginAttemptsNum($ipAddress, $userID)
{
    $this->db->where('ipAddress', $ipAddress);
    $this->db->or_where('userID', $userID);
    $query = $this->db->get($this->usersLoginsAttempts);
    if ($query->num_rows > 0)
    {
        return $query->num_rows;          
    }
    else
    {
        return 0;
    }        
}

Fields: id, userID, ipAddress, datetime

ユーザーが誤ったログインを行うたびに、ipAddressまたはuserIDのいずれか5つごとにそれを格納するフィールドに別の行が追加されます。したがって、最後の5つしか保存されないため、最後の日時を確認する必要があります。

4

1 に答える 1

1

最初の選択肢は、次の場合にユーザーをロックアウトするかどうかです。

  • コンピューターから5回の無効な試行が行われ、任意のユーザー名(ハッカーを捕まえる可能性が高い)
  • 同じ有効なユーザー名から5回の無効な試行が行われました(ユーザーがユーザー名を知っていて、パスワードを知らないユーザーを捕まえる可能性が高くなります)。

設定したメソッドはこれらのscondです(関数isMaxLoginAttemptsExceeded($ userData-> userID))で判断します)

だから、それに基づいて:

ステージ1:

ユーザーのデータベースに、「invalid_login_count」、「last_invalid」、「attempt」、「locked_out_until」の3つのフィールドを追加します。

ステージ1:

「//ログインに失敗しました」という行の前後で、無効な試行が行われたという事実を記録する必要があります。「invalid_login_count」をインクリメントしてDBに保存し、「last_invalid_attempt」を今すぐに設定します。「invalid_login_count」=5の場合は、「locked_out_until」も時間+5分に更新します。

ステージ2:

「//ログインに成功しました」という行の前後で、「invalid_login_count」、「last_invalid_attempt」、「locked_out_until」の値をクリアします(つまり、リセットします)。

ステージ3:

「last_invalid_attempt」に値があり、5分以内の場合は、「locked_out_until」、「last_invalid_attempt」、「invalid_login_count」の値をクリアします。無効か現在かを問わず、ユーザーの詳細を取得したらすぐにこれを実行します。

ステージ4:

$ this-> auth-> isMaxLoginAttemptsExceeded($ userData-> userID)関数は、「locked_out_until」値を確認する必要があります。>現在の場合、それらはロックアウトされています。

注:これは、ユーザーが5回未満の無効な試行を入力できず、それぞれの間隔が5分未満であることを意味します。それはあなたが求めたものではありませんが(5分間で5回の試行)、最新のすべての試行の時間を保存し、最後の5分間の価値のみを含めるというロジックは少し難しいので、単純にしています。


実際には、IPアドレスでロックアウトすることをお勧めします。これは、試行回数をカウントしてIPでロックアウトするための特定のテーブルが必要であり、2か所で更新する必要があるため(ユーザー名が見つからない場合は、またはパスワードが無効な場合)、ユーザー名が有効かどうかを確認する前に、IPがロックされている場合はユーザーを除外する必要があります。それ以外は同じロジックです。

于 2012-05-31T12:13:57.323 に答える