美文网首页
PHP MD5加密 注册登陆(原生)

PHP MD5加密 注册登陆(原生)

作者: 弓长晓 | 来源:发表于2020-03-29 22:00 被阅读0次

    逻辑层

        <?php
    /*
     * @Description: 登陆验证 模块
     * @Author: Fore-Zhang
     * @Date: 2020-03-29 09:28:41
     * @LastEditTime: 2020-03-29 21:45:50
     * @LastEditors: 项目组长
     */
        /* 登陆conn.php*/
        error_reporting(0);
        include '../db/db.php';
        $username=$_POST['username'];
        $password=md5($_POST['password']);
        echo $password;
        $sql="select * from admin where username='".$username."'";
        $res=mysql_query($sql);
        if($_POST['dl']=="登录"){
            if($row=mysql_fetch_array($res)){
                echo '/n';
                echo $row['password'];  
            if($row['password']==$password){
                // $_SESSION['username']=$row['username'];
                header("location:index.php");
            exit();
            }else{
            echo "<script> alert('密码不正确')</script>";
            }
            }else{
            echo "<script> alert('用户名不存在')</script>";
            }
    }
    ?>
    
    <?php
    /*
     * @Description: 注册模块
     * @Author: Fore-Zhang
     * @Date: 2020-03-29 09:28:41
     * @LastEditTime: 2020-03-29 21:45:50
     * @LastEditors: 项目组长
     */
      /* 注册 connLogin.php*/
        header("Content-type: text/html; charset=utf-8");
            $username = $_POST['username'];
            $password = $_POST['password'];
            $hashpwd = md5($password);
            echo "<script>console.log($hashpwd)</script>";
            $repassword = $_POST['repassword'];
            if ($username == ''){
                echo '<script>alert("请输入用户名!");history.go(-1);</script>';
                exit(0);
            }
            if ($password == ''){
                echo '<script>alert("请输入密码");history.go(-1);</script>';
                exit(0);
            }
            if ($password != $repassword){
                echo '<script>alert("密码与确认密码应该一致");history.go(-1);</script>';
                exit(0);
            }
            if($password == $repassword){
                $conn = new mysqli('localhost','root','971023','as');
                if ($conn->connect_error){
                    echo '数据库连接失败!';
                    exit(0);
                }else {
                    $sql = "select username from admin where username = '$_POST[username]'";
                    $result = $conn->query($sql);
                    if (!$result) {
                       printf("Error: %s\n", mysqli_error($conn));
                         exit();
                        }
                    $number = mysqli_num_rows($result);
                    if ($number) {
                        echo '<script>alert("用户名已经存在");history.go(-1);</script>';
                    } else {
                        $sql_insert = "insert into admin (username,password) values('$_POST[username]','$hashpwd')";
                        $res_insert = $conn->query($sql_insert);
                        if ($res_insert) {
                            echo '<script>window.location="login.php";</script>';
                        } else {
                            echo "<script>alert('系统繁忙,请稍候!');</script>";
                        }
                    }
                }
            }else{
                echo "<script>alert('提交未成功!'); history.go(-1);</script>";
            }
    ?>
    

    显示层

    login.php 登陆页 
    <form action="connte.php" method="post">
                        <div class="form-group">
                          <input type="text" class="form-control" id="username" name="username" value="" placeholder="用户名"  aria-describedby="emailHelp" >
                          
                        </div>
                        <div class="form-group">
                          <input type="password" class="form-control"  id="password" name="password" value="" placeholder="密码">
                        </div>
                          <div class="form-check"
                          <label class="switch">
                          <input type="checkbox">
                          <span class="slider round"></span>
                        </label>
                          <label class="form-check-label" for="exampleCheck1">记住选项 </label>
                          <label class="forgot-password" ><a href="register.html">注册<a></label>
                        </div>
                        <br>
    <button type="submit"  value="登录" name="dl"  class="btn btn-lg btn-block btn-success">登陆 </button>
                      </form>
    --------------
    注册页
          <!-- Loging form -->
              <form action="conn.php" method="post">
                <div class="form-group">
                  <input type="text" class="form-control" id="username" name="username" value="" placeholder="用户名"
                    aria-describedby="emailHelp">
    
                </div>
                <div class="form-group">
                  <input type="password" class="form-control" id="password" name="password" value="" placeholder="密码">
                </div>
    
                <div class="form-group">
                  <input type="password" class="form-control" id="repassword" name="repassword" value="" placeholder="确认密码">
                </div>
                <div class="form-check">
    
                  <label class="switch">
                    <input type="checkbox">
                    <span class="slider round"></span>
                  </label>
                  <label class="form-check-label" for="exampleCheck1">记住选项 </label>
    
                  <label class="forgot-password"><a href="login.php">注册<a></label>
    
                </div>
    
                <br>
                <button type="submit" value="登录" name="dl" class="btn btn-lg btn-block btn-success">登陆 </button>
              </form>
              <!-- End Loging form -->
    

    相关文章

      网友评论

          本文标题:PHP MD5加密 注册登陆(原生)

          本文链接:https://www.haomeiwen.com/subject/iqdpuhtx.html