Muratcan Yalın
Muratcan Yalın

Reputation: 11

How do I convert Python encryption to PHP?

In short, I want to login on my site and I want to login in encrypted form in php codes. I want to use Base64 and SHA256, SHA 256 for encryption.

I would like to know if it is possible to convert this ciphertext into PHP language, I need to convert the generated passwords to be accepted on my site's login system, but I do not know how to do this.

In Python I have a database with passwords generated with this encryption:

base64.b64encode(hashlib.sha256(hashlib.sha256(password).hexdigest() + "\xf7\x1a\xa6\xde\x8f\x17v\xa8\x03\x9d2\xb8\xa1V\xb2\xa9>\xddC\x9d\xc5\xdd\xceV\xd3\xb7\xa4\x05J\r\x08\xb0").digest())

PHP:

<?php
 if($_POST){
     $name = trim($_POST["name"]);
     $sifre = trim($_POST["sifre"]);

    if(!$name || !$sifre){

        echo '<div class="hata">kullancı adı ve sifre bos bırakılamaz</div>';


    }else {

        $uye = $db->prepare("select * from users where Username=? and Password=? and uye_onay=?");
        $uye->execute(array($name,$sifre,1));
        $z = $uye->fetch(PDO::FETCH_ASSOC);
        $x = $uye->rowCount();

        if($x){

            $_SESSION["uye"] = $z["Username"];
            $_SESSION["eposta"] = $z["uye_eposta"];
            $_SESSION["rutbe"] = $z["uye_rutbe"];
            $_SESSION["id"] = $z["PlayerID"];

            header("location:index.php");

        }elseif($z["uye_onay"] == 0){

            echo '<div class="hata">uyeliğiniz onaylanmadı yonetici onayını bekleyin..</div>';

        } else {

            echo '<div class="hata">uye adı yada sifreniz yanlıs</div>';

        }
    }   

?>

Upvotes: 1

Views: 686

Answers (1)

Ermat Kiyomov
Ermat Kiyomov

Reputation: 151

Your Python code:

base64.b64encode(hashlib.sha256(hashlib.sha256(password).hexdigest() + "\xf7\x1a\xa6\xde\x8f\x17v\xa8\x03\x9d2\xb8\xa1V\xb2\xa9>\xddC\x9d\xc5\xdd\xceV\xd3\xb7\xa4\x05J\r\x08\xb0").digest())

PHP equivalent:

base64_encode(
  hash('sha256',
    hash('sha256', $password) . "\xf7\x1a\xa6\xde\x8f\x17v\xa8\x03\x9d2\xb8\xa1V\xb2\xa9>\xddC\x9d\xc5\xdd\xceV\xd3\xb7\xa4\x05J\r\x08\xb0", 
    TRUE
  )
);

Upvotes: 2

Related Questions