{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zf2/issues/7175","labels_url":"https://api.github.com/repos/zendframework/zf2/issues/7175/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zf2/issues/7175/comments","events_url":"https://api.github.com/repos/zendframework/zf2/issues/7175/events","html_url":"https://github.com/zendframework/zf2/pull/7175","id":56224162,"number":7175,"title":"Reduce iteration when attempt to authenticate user","user":{"login":"teknoman","id":4273323,"avatar_url":"https://avatars.githubusercontent.com/u/4273323?v=3","gravatar_id":"","url":"https://api.github.com/users/teknoman","html_url":"https://github.com/teknoman","followers_url":"https://api.github.com/users/teknoman/followers","following_url":"https://api.github.com/users/teknoman/following{/other_user}","gists_url":"https://api.github.com/users/teknoman/gists{/gist_id}","starred_url":"https://api.github.com/users/teknoman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teknoman/subscriptions","organizations_url":"https://api.github.com/users/teknoman/orgs","repos_url":"https://api.github.com/users/teknoman/repos","events_url":"https://api.github.com/users/teknoman/events{/privacy}","received_events_url":"https://api.github.com/users/teknoman/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zendframework/zf2/labels/Authentication","name":"Authentication","color":"008000"},{"url":"https://api.github.com/repos/zendframework/zf2/labels/awaiting%20author%20updates","name":"awaiting author updates","color":"e11d21"},{"url":"https://api.github.com/repos/zendframework/zf2/labels/Db","name":"Db","color":"008000"},{"url":"https://api.github.com/repos/zendframework/zf2/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-02T11:18:57Z","updated_at":"2015-02-03T13:24:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/zendframework/zf2/pulls/7175","html_url":"https://github.com/zendframework/zf2/pull/7175","diff_url":"https://github.com/zendframework/zf2/pull/7175.diff","patch_url":"https://github.com/zendframework/zf2/pull/7175.patch"},"body":"In case of (many) ambiguous identities we can reduce iteration on *authenticate()* method by setting ORDER clause to SELECT query"},"comment":{"url":"https://api.github.com/repos/zendframework/zf2/issues/comments/72649246","html_url":"https://github.com/zendframework/zf2/pull/7175#issuecomment-72649246","issue_url":"https://api.github.com/repos/zendframework/zf2/issues/7175","id":72649246,"user":{"login":"teknoman","id":4273323,"avatar_url":"https://avatars.githubusercontent.com/u/4273323?v=3","gravatar_id":"","url":"https://api.github.com/users/teknoman","html_url":"https://github.com/teknoman","followers_url":"https://api.github.com/users/teknoman/followers","following_url":"https://api.github.com/users/teknoman/following{/other_user}","gists_url":"https://api.github.com/users/teknoman/gists{/gist_id}","starred_url":"https://api.github.com/users/teknoman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teknoman/subscriptions","organizations_url":"https://api.github.com/users/teknoman/orgs","repos_url":"https://api.github.com/users/teknoman/repos","events_url":"https://api.github.com/users/teknoman/events{/privacy}","received_events_url":"https://api.github.com/users/teknoman/received_events","type":"User","site_admin":false},"created_at":"2015-02-03T13:24:48Z","updated_at":"2015-02-03T13:24:48Z","body":"@Ocramius assume that you have records in the table users with same credentials but with different roles:\r\n\r\nid | email | password | role\r\n------------ | ------------- | -------------- | --------------\r\n1 | mymail@domain.tld | mycryptedpwd | guest\r\n2 | mymail@domain.tld | mycryptedpwd | user\r\n3 | mymail@domain.tld | mycryptedpwd | pro\r\n\r\nWhen the user with role *pro* tries to login, the resultant query built in *authenticateCreateSelect()* method in Zend\\Authentication\\Adapter\\DbTable\\CredentialTreatmentAdapter.php (row 79) is:\r\n\r\nSELECT users.*, (CASE WHEN PASSWORD = 'mycryptedpwd' AND role = 'pro' THEN 1 ELSE 0 END) AS zend_auth_credential_match FROM users WHERE EMAIL = 'mymail@domain.tld'; as shown below:\r\n\r\nid | email | password | role | zend_auth_credential_match\r\n------------ | ------------- | -------------- | -------------- | -------------\r\n1 | mymail@domain.tld | mycryptedpwd | guest | 0\r\n2 | mymail@domain.tld | mycryptedpwd | user | 0\r\n3 | mymail@domain.tld | mycryptedpwd | pro | 1\r\n\r\nif we add a ORDER clause (ORDER BY zend_auth_credential_match DESC, the code in this PR), in case of matched credentials, the number of iterations in method *authenticate()* (row 245 of AbstractAdapter.php) can be reduced to 1, saving time and memory."}}