首页  >  文章  >  后端开发  >  php检测账号密码是否匹配

php检测账号密码是否匹配

尚
原创
2019-10-29 11:31:372560浏览

php检测账号密码是否匹配

PHP检测账号密码是否匹配:

推荐:php服务器

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(&#39;Login/lusername&#39;)}",{username:username},function(data) {
        $("#username").html(data)
    })
}
function rpassword(obj){
    var password=$(obj).val();
    $.post("{:U(&#39;Login/lpassword&#39;)}",{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="登录"/>
               
               
               
        <input name="submit" type="submit" value="注册"/>
    </p>
    </form>
</div>

PHP代码:

<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function login(){
        if($_POST){
            $where[&#39;username&#39;]=$_POST[&#39;username&#39;];
            $where[&#39;password&#39;]=md5("php100".$_POST[&#39;password&#39;]);
            $users=M(&#39;users&#39;)->where($where)->select();
            if($users){
                $_SESSION[&#39;id&#39;]=$users[&#39;id&#39;];
                $_SESSION[&#39;user_shell&#39;]=md5($users[&#39;username&#39;].$users[&#39;password&#39;]);
                $this->redirect(&#39;Index/index&#39;);
            }else{
                echo "<script type=&#39;text/javascript&#39;>alert(&#39;用户名或密码错误&#39;);window.history.go(-1);</script>";
            }
        }else{
            $this->display();
        }
    }
    public function lusername(){
        $where[&#39;username&#39;]=I(&#39;username&#39;);
        $users=M(&#39;users&#39;)->where($where)->select();
        if(!$users){
            echo "用户名错误";
        }
    }
    public function lpassword(){
        $where[&#39;password&#39;]=I(&#39;password&#39;);
        $users=M(&#39;users&#39;)->where($where)->select();
        if(!$users){
            echo "密码错误";
        }
    }
}

以上是php检测账号密码是否匹配的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn