2014-01-29 35 views
0

我对我的问题存在一些问题。这个想法是从登录视图获取用户输入,并将其与数据库中的记录进行比较。请问我该怎么做?从登录页面获取用户输入,并将其与数据库中的值进行比较

这是我LoginController.php代码

function login(){ 
$this->loadModel('Login'); 
$user = $this->request->data ['Login'] ['Username']; 
$pass = $this->request->data ['Login'] ['Password']; 

    $this->Login->find('all', array(
    'conditions' => array('username' => $dbuser,'password' => $dbpass))                                                                                                                                    
); 

if ($user == $dbuser){ 

if($pass == $dbpass){ 
$this->Session->setFlash('Welcome, ' . $user); 
$this->redirect(array('action' => 'home')); 
$this ->set('title_for_layout', 'Homepage'); } 
} 
else 
    { 
    $this->Session->setFlash('Error Login In!'); 
    } 

    } 

这是我View.ctp代码

<html> 
<body background="bgimage.jpg"> 
<center> 
<strong><h2>LOGIN FORM</h2><strong> 

<?php 
echo $this->form->create('Login', array('action' => 'login')); 
echo $this->form->input('Username'); ?> <br> 
<?php echo $this->form->input('Password'); ?> <br> 
<?php echo $this->form->end('Login'); 
?> 
<br><br> 
    <?php echo $this->html->link ('Forgot Password?', array('action' =>'forgot')); ?> 
</center> 

<p> <?php echo $this->html->link ('Create Account', array('action' =>'add')); ?> </p> 
</body> 
</html> 

请帮

+0

'$ dbuser'和'$ dbpass'来自哪里?他们是正确的密码在数据库中应该被散列,所以你nedd比较散列版本的提交的密码 – lp1051

回答

0

为什么不使用邮政变量?

$username = $_POST['Username']; 
$password = $_POST['Password']; 
0

由于安全原因,密码必须通过POST方法发送到php。 此外,还有函数md5 - 使用它来加密您的密码,并将其作为加密值保存到服务器上的数据库。 当用户发送密码时使用md5,并将其与数据库值进行比较。

对于登录,最好找到好的captca(确保你是人类,而不是尝试登录的机器人/软件)。

祝你好运!

相关问题