duanji8887 2019-07-12 20:12
浏览 70

检查md5的礼物

Newish to PHP so still in the learning stages. I have been asked to help on a website that was built years ago, and as such the DB is still using MD5, which I need to sort I’ve written some code, which mostly works fine just stuck on the last part. In summary this is what I’m trying to do

User logs in ( so sql gets info from DB) Check password from this result & if starts with XYZ go to this page, if not go to other page. Code is below, being done on local serve till I get working

   <!DOCTYPE html>
<html>
<body>


<?php



function begnWith($str, $begnString) {
   $len = strlen($begnString);
   return (substr($str, 0, $len) ===    

$beg string);
}


// if(begnWith($text,"$2y"))

    //header("Location:     

http://www.bbc.co.uk");

// else
   //echo "Old MD5";
?>


<?php

$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "login";

// Create connection
$conn = new mysqli($servername,    

$username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn-   

>connect_error);
} 


$sql = "SELECT * FROM users   

WHERE username='davsas';";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result-   

>fetch_assoc()) {
        // echo "<br> id: ". $row["id"]. " -    

Name: ". $row["username"]. " " .  

$row["password"] . "<br>";
        $datas[] = $row;

    }
}

 foreach ($datas[0] as $data) {
    echo $data['password'];

}

if(begnWith($data['password'],"$2y"))

    header("Location:   

http://www.bbc.co.uk");

 else
   echo "Old MD5";


//foreach ($datas[0] as $data) {
    //echo $data;
//}

//foreach ($datas as $data) {
//    echo $data['password'];
//}
$conn->close();
?> 

</body>
</html>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog