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?
cakephp cakephp-3.0
add a comment |
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?
cakephp cakephp-3.0
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
add a comment |
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?
cakephp cakephp-3.0
$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
cakephp cakephp-3.0
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
add a comment |
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
add a comment |
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')))
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
add a comment |
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')))
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
add a comment |
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')))
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
add a comment |
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')))
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')))
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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