2012-04-04 9 views
0

나는 웹 사이트를 운영 했으므로 액세스가 제한되어야합니다.
따라서 페이지를로드하기 전에 페이지로드 전에 클라이언트의 usernamepassword 및 해당 페이지의 specific password이라는 세 개의 필드를 사용하여 액세스를 제한해야합니다.이 세 가지는 저에게 생성되어 데이터베이스에 저장됩니다.URL에 대한 비밀번호 보호

저는 Javascript와 PHP에 대한 기본적인 지식을 가지고 있습니다.

제 아이디어는 페이지로드 전입니다. 자바 스크립트는 사용자가 입력 한 세 개의 필드 값을 가져와야하며, PHP가 데이터베이스를 사용하여 유효성을 검사해야합니다. 일치하는 경우 페이지가로드되어야합니다. 거절 당했다.

간단히 말하면 URL을 방문하고 데이터베이스에 대한 페이지로드 연결이 이루어져야하고 사용자/클라이언트가 입력해야합니다. 3 개의 필드가 있어야하며 PHP에 의한 MYSQL 데이터베이스로 확인되어야하며 인증에 성공하면 페이지가 표시되어야합니다.

코드 제안을 제안하십시오.

<?php 
function login($username,$password,$salt,$db,$table,$usercolumn,$passwordcolumn,$con) 
{ 
    $user=mysql_real_escape_string($username); 
    $password=mysql_real_escape_string($password); 
    $db=mysql_select_db($db,$con); 
    if(!$db) 
    { 
     return "connection error"; 
    } 
    else 
    { 
     $sql="SELECT * FROM `$table` WHERE `$usercolumn`='$user';"; 
     $enc=$password; 

    foreach($salt as $value) 
    { 
     if($value=="md5") 
     { 
      $enc=md5($enc); 
     }else 
     { 
      $enc=crypt($enc,$value); 
     } 
    } 
     $resource=mysql_query($sql); 
     $row=mysql_fetch_array($resource); 
     $passdb=$row[$passwordcolumn]; 
     if($passdb==$enc) 
     { 
      $sucess=true; 
     }else 
     { 
      $sucess=false; 
     } 


    } 
    return $sucess; 
} 
?> 

당신은이를 사용할 수 있으며,이 true를 돌려주는 경우, 그 이름을 의미와 비밀번호는 세 번째를 확인해야 지금 올바른 : 나는 당신이 사용할 수있는 기능을 만든 사전 :

+1

여기에 질문이 있습니까? –

답변

2

을 감사드립니다 이 "logger.php"에 이름을 지정하면 옵션 ...
이 기능을 사용하려면, 당신은 사용자 이름과 암호를 수용하기위한,

<?php 
require("logger.php"); 
$enc=array("salt","md5","differentsalt")//your encryption such as if you have encrypted using 'salt' at first then using md5 hash and again 'differentsalt',then you need to give like i have given 

if(login($username,$password,$enc,$db,$table_name,$usercolumn,$passwordcolumn,$con))//$username is the username which user supplied,$password is password user supplied,$enc is the encryption and it must be an array... which is also given above,$db is database name,$table_name is the table where username and encrypted password are stored,$usercolumn is the column name where username are stored, $passwordcolumn is the column where encrypted password are stored, and last $con is the connection identifier, you may have given, $con=mysqli_connect("username","password"); 
//if all the parameters are supplied correctly, it will check for the username and password matching and you will have to check the third option 
{ 
//now validate your third option here... 
//if you are here, that means password and username has matched 

} 
else 
{ 
//this means username and password didnt matched... so output the error 
} 
?> 

파일로 해당 기능을 복사 한 후 다음과 같이 호출 할 필요가 , 너 양식을 작성하고 거기에 암호를 물어 제출할 수 있습니다 ...

관련 문제