简单的PHP mongoDB用户名和密码检查站点 [英] Simple PHP mongoDB Username and Password Check for site
本文介绍了简单的PHP mongoDB用户名和密码检查站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我有一个名为:'members'的集合,因为我为每个'members'提供了一个用户名和密码. 我需要知道的是如何检查两者是否匹配,即用户名+密码=成功
So, I have a collection called: 'members' and in that I have a user name and password for each of my 'members'. What I need to know is how do I check to see if the two match i.e. username + password = success
这是我尝试过的方法,它可以正确搜索,只是如果没有用户,它不会返回错误
This is what I have tried and it does the search correctly, just it's not returning the error if no user
public function userlogin($data)
{
$this->data = $data;
$collection = $this->db->members;
// find everything in the collection
$cursor = $collection->find(array("username"=>$this->data['username'], "password"=>$this->data['password']));
$test = array();
// iterate through the results
while( $cursor->hasNext() ) {
$test[] = ($cursor->getNext());
}
//Print Results
if($test == NULL)
{
print "Sorry we are not able to find you";
die;
}
//print json_encode($test);
}
推荐答案
类似以下内容:
$mongo = new Mongo();
$db = $mongo->dbname;
$user = $db->collection->findOne(array("username" => $username, "password" => $password));
if ($user->count() > 0)
return $user;
return null;
或者:
$user = $db->collection->findOne(array("username" => $username, "password" => $password));
$user->limit(1);
if ($user->count(true) > 0)
return $user;
return null;
这篇关于简单的PHP mongoDB用户名和密码检查站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文