2011-12-24 2 views
1

매우 기밀 한 사이트에 로그인 할 수있는 매우 기밀 한 사이트가 있습니다. 사용자가 3 회 로그인 시도를했는지 확인하려면 어떻게해야합니까? 내 디렉토리에서 전체 디렉토리가 삭제됩니다. 이 일을하기가 어렵습니까?로그인 시도가 최대에 도달하면 전체 사이트 디렉토리를 삭제하는 방법

여기 내 로그인 페이지입니다 :

<?php 
require_once('scripts/user_authentication.php'); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<link href='http://fonts.googleapis.com/css?family=Inder' rel='stylesheet' type='text/css'> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Access login</title> 
<link href="../styles/users.css" rel="stylesheet" type="text/css" /> 
<style> 
span {font-family: 'Inder', sans-serif; color: #369; font-style: italic;} 

#login {width: 400px; margin: 60px auto 0 auto; padding: 20px; text-align: center; 
    box-shadow: 0px 9px 21px rgba(0, 0, 0, 0.63); 
    -moz-box-shadow: 0px 9px 21px rgba(0, 0, 0, 0.63); 
    -webkit-box-shadow: 0px 9px 21px rgba(0, 0, 0, 0.63); 
} 

#login p {text-align: left;} 

form {padding: 0; margin: 0; } 
input {margin: 0; padding: 0;} 

h1 { margin: 0 0 20px 0; padding: 0;} 

</style> 


</head> 

<body> 
<div id="login"> 
<h1><span>p*******</span> Partners Only</h1> 
<div id="inner"> 
<?php if ($failed) { ?> 
<p class="warning">Login failed. Try Again. Please contact ******* ***** if you do not know your access information. After multiple attempts this site will self destruct. Thank you for your cooperation.</p> 
<?php } ?> 
<form id="form1" name="form1" method="POST"> 
    <p> 
    <label for="username">Username:</label> 
    <input type="text" name="username" id="username" /> 
    </p> 
    <p> 
    <label for="password">Password:</label> 
    <input type="password" name="password" id="password" /> 
    </p> 
    <p> 
    <input type="submit" name="signin" id="signin" value="Sign in" /> 
    </p> 
</form> 
</div> 
</div> 
</body> 
</html> 

여기 user_authentication : 그것은 매우 위험 코멘트에 언급 된 사람들이 그 일을

<?php 
$failed = FALSE; 
if ($_POST) { 
    if (empty($_POST['username']) || empty($_POST['password'])) { 
    $failed = TRUE; 
    } else { 
    require_once('library.php'); 
    // check the user's credentials 
    try { 
     $auth = Zend_Auth::getInstance(); 
     $adapter = new Zend_Auth_Adapter_DbTable($dbRead, 'users', 'first_name', 'family_name', 'password' 'sha1(?)'); 
     $adapter->setIdentity($_POST['username']); 
     $adapter->setCredential($_POST['password']); 
     $result = $auth->authenticate($adapter); 
     if ($result->isValid()) { 
     $storage = $auth->getStorage(); 
     $storage->write($adapter->getResultRowObject(array(
      'username', 'first_name', 'family_name'))); 
     header('Location: members_only.php'); 
     exit; 
     } else { 
     $failed = TRUE; 
     } 
    } catch (Exception $e) { 
     echo $e->getMessage(); 
    } 
    } 
} 
if (isset($_GET['logout'])) { 
    require_once('library.php'); 
    try { 
    $auth = Zend_Auth::getInstance(); 
    $auth->clearIdentity(); 
    } catch (Exception $e) { 
    echo $e->getMessage(); 
    } 
} 
+0

왜 당신이 디렉토리를 삭제할 것 액세스 할 계정을 잠그고 실제 사용자에 대한 보안 절차를 대답해야? 사용자가 비밀번호를 잊어 버린 경우 또는 다른 사용자가 사용자 이름을 사용하여 페이지에 액세스하려고한다면 어떻게해야합니까? – Virendra

+9

이것은 매우 위험한 접근 방법입니다. 공격자가 서버에서 물건을 삭제하면 실제 사용자가 액세스 할 수 없게됩니다. –

+3

URL을 게시하면 다른 사람들이 테스트 해 줄 것이라고 확신합니다.) – Ram

답변

6

당신의 접근 방식을 (사용자를위한 파일 삭제)은 입니다. 실제적으로 나쁜 실행이지만, 절대적으로 수행해야하는 경우 여기에 한 가지 방법이 있습니다. ...

사용자 이름을 저장하는 데이터베이스 테이블 (또는 기존 테이블의 항목)을 만들고 시도 횟수. 인증하기 전에 시도가 설정된 금액 이하인지 확인하십시오. 인증 부분에서 암호가 틀리면 "시도"열을 증가시킵니다. 사용자가 성공적으로 로그인 할 때마다 다시 0으로 설정됩니다. 그들이 시도 횟수를 초과하면 파일을 삭제하거나 필요한 보안 조치를 취하십시오.

이제이 디자인을 개선하기 위해 실제로 서버에서 데이터를 삭제하지 않을 것을 제안합니다. 대신, X 횟수가 실패한 후에는 해당 사용자 이름으로 로그인을 시도하는 사람들에게 증가 된 보안 조치가 적용되는 것이 좋습니다 (예 :;

  • 는 그들이 각 사용자에 대해 여러 개의 암호

  • 저장 "보안 질문에"노력 봇되지 않습니다 알 수 있도록 (예 : "생일 무엇입니까") 보안 문자를 해결하기 위해 사용자가 필요하고, 그들은 그

  • 다시
1

으로. 여전히 정보가 중요하고 로그인 페이지로 링크가 매우 비밀 당신이 다른 곳에 백업이 있다고 생각하는 경우

그러나,이 코드를 수행해야합니다

<?php 
session_start(); // Add this only if you don't have it in some other header files 

// Checking if the session variable exists and initiating it if it does not. 
if (!isset($_SESSION['failed'])) { 
    $_SESSION['failed'] = 0; 
} 

$failed = FALSE; 
if ($_POST) { 
    if (empty($_POST['username']) || empty($_POST['password'])) { 
    $failed = TRUE; 
    } else { 
    require_once('library.php'); 
    // check the user's credentials 
    try { 
     $auth = Zend_Auth::getInstance(); 
     $adapter = new Zend_Auth_Adapter_DbTable($dbRead, 'users', 'first_name', 'family_name', 'password' 'sha1(?)'); 
     $adapter->setIdentity($_POST['username']); 
     $adapter->setCredential($_POST['password']); 
     $result = $auth->authenticate($adapter); 
     if ($result->isValid()) { 

     // Setting the counter to 0 in case of successful login. 
     $_SESSION['failed'] = 0; 

     $storage = $auth->getStorage(); 
     $storage->write($adapter->getResultRowObject(array(
      'username', 'first_name', 'family_name'))); 
     header('Location: members_only.php'); 
     exit; 
     } else { 
     $failed = TRUE; 

     // Increment the failed logins counter at each failed login. 
     $_SESSION['failed']++; 

     // In case of 3 or more failed attempts 
     if ($_SESSION['failed'] > 3) { 

      // Remove some directory 
      rmdir("/path/to/the/dir"); 
      $_SESSION['failed'] = 0; 
     } 
     } 
    } catch (Exception $e) { 
     echo $e->getMessage(); 
    } 
    } 
} 
if (isset($_GET['logout'])) { 
    require_once('library.php'); 
    try { 
    $auth = Zend_Auth::getInstance(); 
    $auth->clearIdentity(); 
    } catch (Exception $e) { 
    echo $e->getMessage(); 
    } 
} 
+0

모든 아이디어가 매우 나쁘다는 사실에도 불구하고 세션 변수가 존재하지 않으면 세션 변수를 초기화하고 사용자가 성공적으로 인증되면 세션 카운터를 0으로 설정하는 코드 명령어를 추가합니다. –

+0

감사합니다. 경미한 리팩터링이 =) – Dimme

+0

이 코드는 로그인 페이지 안에 있습니까? 또한 이것은 db 정보에 영향을주지 않을 것입니다. –

관련 문제