如何:CakePHP登录没有密码? [英] How to: CakePHP logging in without password?

查看:230
本文介绍了如何:CakePHP登录没有密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种无密码登录用户的方式。



原因是我的网站有phpBB3论坛,用户已经登录那里。所以我现在正在构建一个扩展到网站,而不仅仅是论坛(使用CakePHP)。我想我可以附加自动帐户创建到CakePHP当用户创建一个帐户到论坛(和现有用户的其他链接)。因此,用户将获得具有与他们在论坛中注册的用户名相同的CakePHP帐户。这意味着注册到CakePHP部分网站的唯一方法是先注册论坛。



现在我想通过phpBB3登录来处理整个日志记录,所以用户仍然可以登录论坛,然后我将附加一段代码使用他们用来登录论坛的用户名登录他们到CakePHP部分。



这样我也可以通过他们的状态将用户放到他们自己的ACL组论坛。



这是我的后,我需要知道的方式登录用户这种方式。 我不是在寻找完整的代码我只是寻找一个解释如何我登录用户在CakePHP没有他们有密码。



我还看过 http://面包店。/ / p / b / b / b / b / b / b / b / b / b / b / b / b / b / div> =>

据我所知,Auth需要两个信息来登录。
您可以更改用户表中由auth用哪些字段进行检查。

  $ Auth-> fields = array(
'username'=>'username',
'password'=>'password'
);

所以如果你想根据自己的昵称和shoesize登录用户: p>

  $ Auth-> fields = array(
'username'=>'nickname',
' password'=>'shoesize'
);

重要信息:

AuthComponent期望存储在

(我认为这是一个sha1的密码和Security.salt)



上面的例子中,如果数据库中已经存在任何条目,则必须使用hasizes版本的shoeizes来覆盖其中的shoesize字段。



要生成您自己可以使用 $ Auth-> password('A Password');






快速和脏的



如果您填写用户表中的密码字段,返回值为:
$ Auth-> password(null);



然后您可以使用以下命令: p>

  $ Auth-> login(
array(
'User'=> array b'username'=> USERNAME_FROM_PHPBB3,
'password'=> null


);






减少快速和肮脏






创建新用户时。
将密码字段设置为一些随机输入的md5哈希值。

  $ this-> authUser [$ this - > User-> alias] [$ Auth-> fields ['password']] = $ Auth-> password(md5(rand()。rand())); 






使用phpBB3的用户名检索相关记录
从数据库中的users表。

  $ this-> authUser = $ this-> User-> findByUsername(USERNAME_FROM_PHPBB3); 

如果查询成功登录用户

  if($ this-> authUser){
if($ Auth-> login($ this-> authUser)){
//登录成功
}
}





I'm trying to find a way to log in user without password.

The reason is that I have phpBB3 forums in my site and the users already log in there. So I'm now building an expansion to the site to have more than just the forum (Using CakePHP). I thought that I could attach automatic account creation to CakePHP when user creates an account to forums (And ofcourse other link for the existing users). So the users would get CakePHP account that has the same username that they have registered in forums. That means that the only way to register to CakePHP part of the site would be to register to the forums first.

Now I'd like to handle the whole logging thing by phpBB3 login so users would still login to forums, and then I'd attach a piece of code that would also login them to CakePHP part of the site with the username they used to login to forums.

This way I could do also put users to their own ACL groups by their status in forums.

Thats what I'm after and I need to know the way to login users this way. I'm not looking for complete code I'm just looking for an answer that explains how I log in users in CakePHP without them having passwords at all.

I have also looked http://bakery.cakephp.org/articles/wilsonsheldon/2009/01/13/phpbb3-api-bridge but it just doesn't quite look what I'm looking for...

解决方案

As far as I recall, Auth requires two pieces of info for a login. You can change which fields in the users table are checked by auth with.

$Auth->fields = array(
    'username' => 'username',
    'password' => 'password'
);

So if you you want to be able to log in users according to their nickname and shoesize:

$Auth->fields = array(
    'username' => 'nickname',
    'password' => 'shoesize'
);

IMPORTANT:
The AuthComponent expects the password value stored in the database to be hashed instead of being stored in plaintext.
(I think it is a sha1 of the password and Security.salt)

In the above example, if any entries already existed in the database you'd have to overwrite the shoesize field for each of them with hashed versions of the shoesizes.

To generate a hashed password yourself you can use $Auth->password('A Password');


Quick and Dirty

If you fill the password fields in your users table with the return value of: $Auth->password(null);

Then you can use the following:

$Auth->login(
    array(
        'User'=>array(
            'username'=> USERNAME_FROM_PHPBB3,
            'password'=>null
        )
    )
);


Less Quick and Dirty


When creating a new user. Set the password field to the md5 hash of some random input.

$this->authUser[$this->User->alias][$Auth->fields['password']] = $Auth->password(md5(rand().rand()));


Use the Username from phpBB3 to retrieve the relevant record from the users table in the database.

$this->authUser = $this->User->findByUsername( USERNAME_FROM_PHPBB3 );

If the query was successful Log in the user

if($this->authUser){
    if($Auth->login($this->authUser)){
        // Login Successful
    }
}


这篇关于如何:CakePHP登录没有密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆