2011-12-24 9 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

あなたのアプローチ(ユーザーのファイルを削除する)は実際には悪い練習ですが、絶対にそれを行う必要がある場合、ここでは1つの方法です...

ユーザー名とパスワードを保存するデータベーステーブルを作成します。試行回数認証する前に、試行が一定量以下であることを確認してください。認証部で、パスワードが間違っている場合は、「試行」列を増やします。ユーザーが正常にログインすると、再びゼロに設定されます。試行回数を超えた場合は、ファイルを削除するか、必要なセキュリティ対策を講じてください。

ここで、このデザインを改善するために、サーバー上のデータを実際に削除しないことをお勧めします。代わりに、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情報の権利に影響しませんか? –

関連する問題