How to choose one field from one retrieved row in CakePHP?











up vote
0
down vote

favorite












$users = TableRegistry::get('Users');
if ($this->request->data) {
$query = $users->findByEmail($this->request->getData('email'));


In the code above, I have retrieved one row from my table where the user's email matches the requested email.



Next, I want to write the code below to check if the password of the selected user is same as the requested password.



PasswordOfSelectedRow == md5($this->request->getData('password')))


What should I put instead of PasswordOfSelectedRow?










share|improve this question






















  • Why are you not using Auth component? What you are doing seems to easily introduce large security issues into the app.
    – mark
    Nov 12 at 15:12










  • @mark OK thanks for the tip, I will be looking more into Auth components
    – JAVAnewbie
    Nov 13 at 4:34

















up vote
0
down vote

favorite












$users = TableRegistry::get('Users');
if ($this->request->data) {
$query = $users->findByEmail($this->request->getData('email'));


In the code above, I have retrieved one row from my table where the user's email matches the requested email.



Next, I want to write the code below to check if the password of the selected user is same as the requested password.



PasswordOfSelectedRow == md5($this->request->getData('password')))


What should I put instead of PasswordOfSelectedRow?










share|improve this question






















  • Why are you not using Auth component? What you are doing seems to easily introduce large security issues into the app.
    – mark
    Nov 12 at 15:12










  • @mark OK thanks for the tip, I will be looking more into Auth components
    – JAVAnewbie
    Nov 13 at 4:34















up vote
0
down vote

favorite









up vote
0
down vote

favorite











$users = TableRegistry::get('Users');
if ($this->request->data) {
$query = $users->findByEmail($this->request->getData('email'));


In the code above, I have retrieved one row from my table where the user's email matches the requested email.



Next, I want to write the code below to check if the password of the selected user is same as the requested password.



PasswordOfSelectedRow == md5($this->request->getData('password')))


What should I put instead of PasswordOfSelectedRow?










share|improve this question













$users = TableRegistry::get('Users');
if ($this->request->data) {
$query = $users->findByEmail($this->request->getData('email'));


In the code above, I have retrieved one row from my table where the user's email matches the requested email.



Next, I want to write the code below to check if the password of the selected user is same as the requested password.



PasswordOfSelectedRow == md5($this->request->getData('password')))


What should I put instead of PasswordOfSelectedRow?







cakephp cakephp-3.0






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 18:44









JAVAnewbie

124




124












  • Why are you not using Auth component? What you are doing seems to easily introduce large security issues into the app.
    – mark
    Nov 12 at 15:12










  • @mark OK thanks for the tip, I will be looking more into Auth components
    – JAVAnewbie
    Nov 13 at 4:34




















  • Why are you not using Auth component? What you are doing seems to easily introduce large security issues into the app.
    – mark
    Nov 12 at 15:12










  • @mark OK thanks for the tip, I will be looking more into Auth components
    – JAVAnewbie
    Nov 13 at 4:34


















Why are you not using Auth component? What you are doing seems to easily introduce large security issues into the app.
– mark
Nov 12 at 15:12




Why are you not using Auth component? What you are doing seems to easily introduce large security issues into the app.
– mark
Nov 12 at 15:12












@mark OK thanks for the tip, I will be looking more into Auth components
– JAVAnewbie
Nov 13 at 4:34






@mark OK thanks for the tip, I will be looking more into Auth components
– JAVAnewbie
Nov 13 at 4:34














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










The following line returns a query object from a dynamic finder



$query = $users->findByEmail($this->request->getData('email'));


From the docs:




Once you have a query object from a dynamic finder, you’ll need to call first() if you want the first result.




So you could write something like this to retrieve the user:



$user = $query->first();


And then to compare to the request data:



$user->password == md5($this->request->getData('password')))





share|improve this answer

















  • 1




    But for the sake of everything holy and sacred, please don't use MD5 hashed passwords!
    – ndm
    Nov 9 at 23:30






  • 1




    @ndm lol can you elaborate on why md5 shouldn't be used?
    – JAVAnewbie
    Nov 10 at 2:49






  • 1




    @JAVAnewbie Because MD5 is very fast and cryptographically weak. The MD5 algorithm's collision resistance has long been cracked (ie it's possible to generate the same hash for different input), and an average modern GPU can calculate billions of MD5 hashes per second, making bruteforce attacks extremely cheap, especially when no salt is being used, which also makes the hashes a good target for rainbow tables.
    – ndm
    Nov 10 at 12:58






  • 1




    @JAVAnewbie When hasing passwords, always use an algorithm that is as expensive as possible, for example bcrypt. CakePHP ships with a password hasher/validator that uses bcrypt by default.
    – ndm
    Nov 10 at 16:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231635%2fhow-to-choose-one-field-from-one-retrieved-row-in-cakephp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










The following line returns a query object from a dynamic finder



$query = $users->findByEmail($this->request->getData('email'));


From the docs:




Once you have a query object from a dynamic finder, you’ll need to call first() if you want the first result.




So you could write something like this to retrieve the user:



$user = $query->first();


And then to compare to the request data:



$user->password == md5($this->request->getData('password')))





share|improve this answer

















  • 1




    But for the sake of everything holy and sacred, please don't use MD5 hashed passwords!
    – ndm
    Nov 9 at 23:30






  • 1




    @ndm lol can you elaborate on why md5 shouldn't be used?
    – JAVAnewbie
    Nov 10 at 2:49






  • 1




    @JAVAnewbie Because MD5 is very fast and cryptographically weak. The MD5 algorithm's collision resistance has long been cracked (ie it's possible to generate the same hash for different input), and an average modern GPU can calculate billions of MD5 hashes per second, making bruteforce attacks extremely cheap, especially when no salt is being used, which also makes the hashes a good target for rainbow tables.
    – ndm
    Nov 10 at 12:58






  • 1




    @JAVAnewbie When hasing passwords, always use an algorithm that is as expensive as possible, for example bcrypt. CakePHP ships with a password hasher/validator that uses bcrypt by default.
    – ndm
    Nov 10 at 16:31















up vote
1
down vote



accepted










The following line returns a query object from a dynamic finder



$query = $users->findByEmail($this->request->getData('email'));


From the docs:




Once you have a query object from a dynamic finder, you’ll need to call first() if you want the first result.




So you could write something like this to retrieve the user:



$user = $query->first();


And then to compare to the request data:



$user->password == md5($this->request->getData('password')))





share|improve this answer

















  • 1




    But for the sake of everything holy and sacred, please don't use MD5 hashed passwords!
    – ndm
    Nov 9 at 23:30






  • 1




    @ndm lol can you elaborate on why md5 shouldn't be used?
    – JAVAnewbie
    Nov 10 at 2:49






  • 1




    @JAVAnewbie Because MD5 is very fast and cryptographically weak. The MD5 algorithm's collision resistance has long been cracked (ie it's possible to generate the same hash for different input), and an average modern GPU can calculate billions of MD5 hashes per second, making bruteforce attacks extremely cheap, especially when no salt is being used, which also makes the hashes a good target for rainbow tables.
    – ndm
    Nov 10 at 12:58






  • 1




    @JAVAnewbie When hasing passwords, always use an algorithm that is as expensive as possible, for example bcrypt. CakePHP ships with a password hasher/validator that uses bcrypt by default.
    – ndm
    Nov 10 at 16:31













up vote
1
down vote



accepted







up vote
1
down vote



accepted






The following line returns a query object from a dynamic finder



$query = $users->findByEmail($this->request->getData('email'));


From the docs:




Once you have a query object from a dynamic finder, you’ll need to call first() if you want the first result.




So you could write something like this to retrieve the user:



$user = $query->first();


And then to compare to the request data:



$user->password == md5($this->request->getData('password')))





share|improve this answer












The following line returns a query object from a dynamic finder



$query = $users->findByEmail($this->request->getData('email'));


From the docs:




Once you have a query object from a dynamic finder, you’ll need to call first() if you want the first result.




So you could write something like this to retrieve the user:



$user = $query->first();


And then to compare to the request data:



$user->password == md5($this->request->getData('password')))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 22:52









bill

1,27111023




1,27111023








  • 1




    But for the sake of everything holy and sacred, please don't use MD5 hashed passwords!
    – ndm
    Nov 9 at 23:30






  • 1




    @ndm lol can you elaborate on why md5 shouldn't be used?
    – JAVAnewbie
    Nov 10 at 2:49






  • 1




    @JAVAnewbie Because MD5 is very fast and cryptographically weak. The MD5 algorithm's collision resistance has long been cracked (ie it's possible to generate the same hash for different input), and an average modern GPU can calculate billions of MD5 hashes per second, making bruteforce attacks extremely cheap, especially when no salt is being used, which also makes the hashes a good target for rainbow tables.
    – ndm
    Nov 10 at 12:58






  • 1




    @JAVAnewbie When hasing passwords, always use an algorithm that is as expensive as possible, for example bcrypt. CakePHP ships with a password hasher/validator that uses bcrypt by default.
    – ndm
    Nov 10 at 16:31














  • 1




    But for the sake of everything holy and sacred, please don't use MD5 hashed passwords!
    – ndm
    Nov 9 at 23:30






  • 1




    @ndm lol can you elaborate on why md5 shouldn't be used?
    – JAVAnewbie
    Nov 10 at 2:49






  • 1




    @JAVAnewbie Because MD5 is very fast and cryptographically weak. The MD5 algorithm's collision resistance has long been cracked (ie it's possible to generate the same hash for different input), and an average modern GPU can calculate billions of MD5 hashes per second, making bruteforce attacks extremely cheap, especially when no salt is being used, which also makes the hashes a good target for rainbow tables.
    – ndm
    Nov 10 at 12:58






  • 1




    @JAVAnewbie When hasing passwords, always use an algorithm that is as expensive as possible, for example bcrypt. CakePHP ships with a password hasher/validator that uses bcrypt by default.
    – ndm
    Nov 10 at 16:31








1




1




But for the sake of everything holy and sacred, please don't use MD5 hashed passwords!
– ndm
Nov 9 at 23:30




But for the sake of everything holy and sacred, please don't use MD5 hashed passwords!
– ndm
Nov 9 at 23:30




1




1




@ndm lol can you elaborate on why md5 shouldn't be used?
– JAVAnewbie
Nov 10 at 2:49




@ndm lol can you elaborate on why md5 shouldn't be used?
– JAVAnewbie
Nov 10 at 2:49




1




1




@JAVAnewbie Because MD5 is very fast and cryptographically weak. The MD5 algorithm's collision resistance has long been cracked (ie it's possible to generate the same hash for different input), and an average modern GPU can calculate billions of MD5 hashes per second, making bruteforce attacks extremely cheap, especially when no salt is being used, which also makes the hashes a good target for rainbow tables.
– ndm
Nov 10 at 12:58




@JAVAnewbie Because MD5 is very fast and cryptographically weak. The MD5 algorithm's collision resistance has long been cracked (ie it's possible to generate the same hash for different input), and an average modern GPU can calculate billions of MD5 hashes per second, making bruteforce attacks extremely cheap, especially when no salt is being used, which also makes the hashes a good target for rainbow tables.
– ndm
Nov 10 at 12:58




1




1




@JAVAnewbie When hasing passwords, always use an algorithm that is as expensive as possible, for example bcrypt. CakePHP ships with a password hasher/validator that uses bcrypt by default.
– ndm
Nov 10 at 16:31




@JAVAnewbie When hasing passwords, always use an algorithm that is as expensive as possible, for example bcrypt. CakePHP ships with a password hasher/validator that uses bcrypt by default.
– ndm
Nov 10 at 16:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231635%2fhow-to-choose-one-field-from-one-retrieved-row-in-cakephp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff