尝试使用localhost数据库验证电子邮件和密码

时间:2013-11-28 21:42:12

标签: php jquery-mobile authentication cordova

您好我一直在尝试为我的phonegap移动应用程序创建身份验证登录,但是在我的网络浏览器上进行测试时,当我在登录表单中输入电子邮件和密码的值(与存储在localhost数据库中的值完全相同)时总是会收到一条警告,提示“您输错了电子邮件和密码”。

我强烈认为它与我的login.js文件有关

$(function(){
    $('form').submit(function(){

    if(validateEmail() && validateUserPassword())
    {
    $.post('libs/auth.php',$('form').serialize(),function(response){
    if(response == 'true')
    {
    alert('You Have logged in successfully');
    setTimeout(function(){
        $.mobile.changePage('index.php', { transition: "slide"});
        },2000);
    }
    else
    {
    alert('You have entered the wrong Email and Password');
    }
    });
    }

    validateEmail();
    function validateEmail(){
    if($('#email').val().length == 0)
    {
    alert('Email is empty');
    return false;
    }
    else
    {
    return true;
    }


    }
    validateUserPassword();
    function validateUserPassword(){
    if($('#password').val().length == 0)
    {
    alert('Password is empty');
    return false;
    }
    else
    {
    return true;
    }

    }



    })
})

如果这不是问题,我将包括各种其他相关的代码:

来自login.php的

登录按钮

<div id="loginButtonDiv" data-role="field-contain">
    <button name="login" type="submit" data-inline="true">Log-In</button>
    </div> <!-- End login button div -->

数据库类(class.database.php)

<?php

    class ManageDatabase{

    protected $db_conn;
    protected $db_host = 'localhost';
    protected $db_name = 'users';
    protected $db_user = 'root';
    protected $db_pass = '';

    function connect(){
        try{
            $this->db_conn = new PDO("mysql:host=$this->db_host;dbname=$this->db_name",$this->db_user,$this->db_pass);
            return $this->db_conn;


        }
        catch(PDOException $e){
                return $e->getMessage();

        }

        }
    }


?>

class.manageUsers.php

<?php

    include_once( 'class.database.php' );


    class ManageUsers{
        protected $link;    
        function __construct(){

        $db_conn = new ManageDatabase;
        $this->link = $db_conn->connect();
        return $this->link;

}
function loginUsers($email,$password)
        {
        $query = $this->link->query("SELECT * FROM users WHERE email = '$email' AND password = '$password' LIMIT 1");
        $rowCount = $query->rowCount();
        return $rowCount;

        }
}

?>

auth.php文件

<?php
    if($_POST)
    {

    include_once( '../core/class.manageUsers.php' );

    $email = trim($_POST['email']);
    $password = trim($_POST['password']);

    if(empty($email) && empty($password))
    {
        echo 'All fields are required';
        }
        else{
            $password = md5($password);
            $init = new ManageUsers;
            $login = $init->loginUsers($email,$password);

            if($login == 1)
            {
            echo 'true';

            }
            else{
            echo 'invalid credentials';
            }
}
}


?>

非常感谢任何解决此问题的帮助!

0 个答案:

没有答案