php檢測賬號密碼是否匹配

2020-07-16 10:06:47

HTML程式碼:

<style>
    #login{width: 250px;height: 120px;background-color: aquamarine;position: fixed;top: 0px;left: 0px;right: 0px;bottom: 0px;margin: auto;padding:50px;text-align: left;}
</style>
<script type="text/javascript" src="__PUBLIC__/js/jquery-3.2.1.js"></script>
<script type="text/javascript">
function rusername(obj){
    var username=$(obj).val();
    $.post("{:U('Login/lusername')}",{username:username},function(data) {
        $("#username").html(data)
    })
}
function rpassword(obj){
    var password=$(obj).val();
    $.post("{:U('Login/lpassword')}",{username:password},function(data) {
        $("#password").html(data)
    })
}
</script>
<div id="login">
    <form action="__ACTION__" method="post">
    <p><input name="username" type="text" value="" size="25" placeholder="填寫使用者名稱" onblur="rusername(this);"/><br/><span id="username" style="font-size:12px;color:red;"></span></p>
    <p><input name="password" type="password" value="" size="25" placeholder="輸入密碼" onblur="rpassword(this);"/><br/><span id="password" style="font-size:12px;color:red;"></span></p>
    <p><input name="submit" type="submit" value="登入"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="submit" type="submit" value="註冊"/>
    </p>
    </form>
</div>

PHP程式碼:

<?php
namespace HomeController;
use ThinkController;
class LoginController extends Controller {
    public function login(){
        if($_POST){
            $where['username']=$_POST['username'];
            $where['password']=md5("php100".$_POST['password']);
            $users=M('users')->where($where)->select();
            if($users){
                $_SESSION['id']=$users['id'];
                $_SESSION['user_shell']=md5($users['username'].$users['password']);
                $this->redirect('Index/index');
            }else{
                echo "<script type='text/javascript'>alert('使用者名稱或密碼錯誤');window.history.go(-1);</script>";
            }
        }else{
            $this->display();
        }
    }
    public function lusername(){
        $where['username']=I('username');
        $users=M('users')->where($where)->select();
        if(!$users){
            echo "使用者名稱錯誤";
        }
    }
    public function lpassword(){
        $where['password']=I('password');
        $users=M('users')->where($where)->select();
        if(!$users){
            echo "密碼錯誤";
        }
    }
}

以上就是php檢測賬號密碼是否匹配的詳細內容,更多請關注TW511.COM其它相關文章!