0

私は Web サイトを持っており、そのアクセスを制限する必要があります。
そのため、ページに入ると、ページが読み込まれる前に、クライアントとそのページの 3 つのフィールドでアクセスを制限する必要がありusernameますpasswordspecific passwordこれら 3 つは私が作成し、データベースに保存されています。

Javascript と PHP の基本的な知識があります。

私の考えは、ページが読み込まれる前に、Javascript はユーザーが入力した 3 つのフィールド値を取得する必要があり、PHP によってデータベースを使用して検証する必要があります。一致した場合は、そのページへのアクセスを拒否する必要があります。

URL のヒットとページ読み込みの前に、データベースへの接続を確立し、ユーザー/クライアントが入力する必要がある 3 つのフィールドを取得し、PHP によって MYSQL データベースで検証し、認証が成功するとページが表示される必要があります。

コードの提案を考え出してください。前もって感謝します :)

4

1 に答える 1

1

私はあなたが使用できる関数を作成しました:

<?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 が返された場合は、ユーザー名とパスワードが正しいことを意味し、3 番目のオプションを検証する必要があります...
この関数を使用するには、その関数をファイルにコピーした後、このように呼び出す必要があります。 「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
}
?>

ユーザー名とパスワードを受け入れるには、フォームを作成し、そこでパスワードを尋ねてから送信することができます...

于 2012-04-04T06:57:03.540 に答える