简体   繁体   中英

cakephp 2 login with username and another field?

I want to use the auth component to handle logging into my site but I want to identify users using their username and another field which they wont see. The reason is I dont want to have to use unique usernames and I dont want to collect email addresses.

Is there a way to make the auth component use the username and another field hidden to the user?

The username has to be unique. This isn't just a restriction of Cake's auth component - it's a restriction of... well... the universe I guess!

The truth is, you already have another field that is hidden to the user, that can uniquely identify users (the id field of the users table). But the problem is, there's no way to use it when users are trying to log in.

Think about it: Lets say you had two users called Fred. But they've each got a different field (id, or some other field) that uniquely identifies them. What happens when they get to the login page? They enter 'Fred'. The system detects there are two Freds. The system knows about both unique fields, for each 'Fred' - but so what? How does it know which unique id to include in the hidden field?

So, usernames have to be unique.

Yes, it is possible but the way what you mention is a security risk. If you still want to do that search for authenticate fields in the CakePHP cookbook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM