0

saltMe() 関数への sha1 ハッシュでパスワードを保護しようとしていますが、パスワード フィールドに何を入力しても、暗号化されたパスワードは同じになります。これは、セキュリティの脆弱性につながる可能性があると思います。

これは私のソルト関数です

**************************************************
* sha1 salt string to make a more secure hash 
***************************************************/
function SaltMe() {
   //Secret keyword encrypted with sha1
   return "4cefe49883b6dd1a00565e2a80fb035f348da3aa";
}

これが私のログインチェックです

$select_user_sql = $this->db->selectSQL("*", "tdic_users", "email = '". $email ."' AND password = '". sha1($this->main->SaltMe($password)) ."'");

パスワードフィールドに何を入力しても、最終的には次のようになります。

1c2c2961d35148e8dfc83c7b31cf144f0987de9d

これは私の暗号化されたパスワードでもあります。しかし、パスワードに合わせたいものを何でも入力できるのは良くありません。

ログイン フォームのアクションは、validatelogin.php で、次のものが含まれます。

$user = new UserHandling();
$user->UserLogMeIn($_POST["login_email"], $_POST["login_password"]);

そしてログイン機能:

 /**********************************************************
     * User login function
     * 
     * @param string    | User's email
     * @param string    | User's password
     **********************************************************/
    function UserLogMeIn($email, $password) {

        $select_user_sql = $this->db->selectSQL("*", "tdic_users", "email = '". $email ."' AND password = '". sha1($this->main->SaltMe($password)) ."'");
        $select_user_result = $this->db->SQLquery($select_user_sql);

        if(mysql_num_rows($select_user_result) < 1) {
            $this->main->txtOutput("Wrong email or password", "TXT_ERR"); //The user typed something wrong.
        } else { 
            while($row = $this->db->SQLfetch($select_user_result)) {
                /*** We will check if user have activated the profile ***/
                if($row["activated"] == 0) {
                    $this->main->txtOutput("Your profile haven't been activated! You need to click on the activation link in the email you recieved upon registration.", "TXT_ERR"); //The user haven't activated the new profile. This is necessary for security / spamming reasons
                    $this->main->JSredirector("http://localhost/test/login.php", 5); //Redirect the user back from where he/she came from
                } else {
                    /*** Everything is in order and we will let the user in ***/

                    $_SESSION["usr_logged_in"] = 1;
                    $_SESSION["user_email"] = $row["email"];
                    $_SESSION["user_id"] = $row["user_id"];
                    $_SESSION["user_name"] = $row["name"];

                    /*** This will just update the last login field in the user table ***/
                    $fields = array("user_last_logged_in" => time());
                    $update_user_sql = $this->db->updateSQL('tdic_users',  'email = "'. $email .'"', $fields);
                    $this->db->SQLquery($update_user_sql);
                }
            }
        }
    }

文字列がどこに設定されているか分からないので常に一致します!

4

3 に答える 3

4

関数は引数を取得しませSaltMeん。常に同じ文字列を返すだけです。そう

SaltMe($password)

あなたが意図したことをしません。

ただし、真面目な話:独自のパスワード ハッシュ スキームを実装しようとするのはやめましょう。実装の間違いについて質問するためにここにいるという事実自体が、十分に理解していないことを十分に証明しているはずです。bcrypt などのライブラリを使用し ( Portable PHP Password Hashing Frameworkには実装があります)、自分で暗号化コードを実装することは避けてください

于 2012-07-05T11:29:55.630 に答える
2

U は、パスをソルトするときに定数文字列を返します。試す

function SaltMe($pass) {
   // Pass salted with Secret keyword encrypted with sha1 
   return "4cefe49883b6dd1a00565e2a80fb035f348da3aa" . $pass;
}

また、SLaks が言ったように、SQLinj があります。また、PDO または mysqli データベース関数を使用することをお勧めします。

于 2012-07-05T11:29:53.040 に答える
1

ソルト文字列をハッシュしているだけで、パスワードの前に付けていません。

"4cefe49883b6dd1a00565e2a80fb035f348da3aa" -> [SHA-1] -> "1c2c2961d35148e8dfc83c7b31cf144f0987de9d"

パスワードをハッシュする前に、ソルトを前に付ける必要があります。

于 2012-07-05T11:31:03.070 に答える