ایجاد تاخیر در لاگین در صورت چند لاگین ناموفق

بازدید50.1kپست ها9آخرین فعالیت9 سال پیش
0
0

سلام
چه جوری میتونم یک فرم ورود (login)بسازم که اگه کاربر رمز رو تا 5 بار اشتباه وارد کرد دیگه به کاربر اجازه ورود نده و پیغامی نمایش بده که شما اجازه ورد ندارید؟

0

سلام
میتونید با استفاده از آیپی کاربر و یا استفاده از کوکی اینکار رو انجام بدید که روش اول بهتره
روش کار خیلی سادست هر دفعه که کاربر رمز رو اشتباه وارد میکنه شما یه عدد به شمارنده اضافه میکنی و تو دیتابیس ذخیره میکنی و هر وقت مقدار شمارنده بیشتر از 5 شد پیام مورد نظر و نمایش بدید.

0

امکان داره کدش و برام قرار بدین؟

0

بله حتما،

<?php
$login_success = tryToLogIn($username, $password);

if (!$login_success) {
    // some kind of unique hash
    $ipusr = getUserIP() . $username;

    DB:update('INSERT INTO failed_logins (ip_usr, failed_attempts) VALUES (:ipusr, 1) ON DUPLICATE KEY UPDATE failed_logins SET failed_attempts = failed_attempts+1 WHERE ip_usr=:ipusr', array((':ipusr' => $ipusr));

    $failed_attempts = DB:selectCell('SELECT failed_attempts WHERE ip_usr=:ipusr', array(':ipusr' => $ipusr));

    sleep($failed_attempts);
    redirect('/login', array('errorMessage' => 'login-fail! ur doin it rong!'));
}
?>

یا

session_start();
 $attempts = "your MySQL result from the attempts table";
 if($attempts < 5){
  //normal login with error message
  $next_attempts = $attempts++;
  //code to write $new_attempts to attempts table
  //set the start of the lockout timer
  if($attempts == 4){
     $_SESSION('timeout') = time();
  }
}
//LOCKED OUT CODE
else{
    echo "sorry you have to wait 15 min to log in again";
    //Check elapsed time
    //10 minute timeout
    if ($_SESSION['timeout'] + 10 * 60 < time()) {
       $attempts = 0;
       //code to write $attempts to table attempts
       session_destroy()
    }
}
0
<br> > بله حتما، ``` <?php $login_success = tryToLogIn($username, $password); if (!$login_success) { // some kind of unique hash $ipusr = getUserIP() . $username; DB:update('INSERT INTO failed_logins (ip_usr, failed_attempts) VALUES (:ipusr, 1) ON DUPLICATE KEY UPDATE failed_logins SET failed_attempts = failed_attempts+1 WHERE ip_usr=:ipusr', array((':ipusr' => $ipusr)); $failed_attempts = DB:selectCell('SELECT failed_attempts WHERE ip_usr=:ipusr', array(':ipusr' => $ipusr)); sleep($failed_attempts); redirect('/login', array('errorMessage' => 'login-fail! ur doin it rong!')); } ?> ``` یا ``` session_start(); $attempts = "your MySQL result from the attempts table"; if($attempts < 5){ //normal login with error message $next_attempts = $attempts++; //code to write $new_attempts to attempts table //set the start of the lockout timer if($attempts == 4){ $_SESSION('timeout') = time(); } } //LOCKED OUT CODE else{ echo "sorry you have to wait 15 min to log in again"; //Check elapsed time //10 minute timeout if ($_SESSION['timeout'] + 10 * 60 < time()) { $attempts = 0; //code to write $attempts to table attempts session_destroy() } } ``` <br>

سلام.....ببخشید به جای getUserIP میشه از این استفاده کرد؟؟

$_SERVER['REMOTE_ADDR']

0

سلام
آره در حقیقت getuserip یه تابع هست که توش از همین کد استفاده شده.

0

باشه...مرسی

0

سلام دوست عزیز
من مدیر نیستم اما معمولا برای تشکر از دکمه تشکر استفاده میکنن :smile16:

0
<br> > سلام دوست عزیز من مدیر نیستم اما معمولا برای تشکر از دکمه تشکر استفاده میکنن :smile16: <br> ایشالا دفعه بعد حتما استفاده میکنم
0

خیلی سپاس گذارم

سوال برنامه نویسی دارید؟

ندونستن عیب نیست، نپرسیدن چرا!

خوش آمدید

برای طرح سوال، ایجاد بحث و فعالیت در سایت نیاز است ابتدا وارد حساب کاربری خود شوید. در صورتی که هنوز عضو سایت نیستید میتوانید در عرض تنها چند ثانیه ثبت نام کنید.