Not able to compare my database password and input field password
My input password and database password are same then also function is returning false. Here compare method is not working properly.I am getting false in return everytime while I am providing correct password.
app.post('/login', (req, res) => {
const username = req.body.username;
const password = req.body.password;
db.query('SELECT * FROM dataa WHERE username = ?',[username], function (error, rows, fields) {
if (error) {
// console.log("error ocurred",error);
res.send({
"code":400,
"failed":"error ocurred"
})
}else{
// console.log('The solution is: ', results);
if(rows.length >0){
console.log(bcrypt.compareSync(password, rows[0].password));
if(bcrypt.compareSync(password, rows[0].password)){
res.send({
"code":200,
"success":"login sucessfull"
});
}
else{
res.send({
"code":204,
"success":"Email and password does not match"
});
}
}
else{
res.send({
"code":204,
"success":"Email does not exits"
});
}
}
});
})
mysql node.js
|
show 1 more comment
My input password and database password are same then also function is returning false. Here compare method is not working properly.I am getting false in return everytime while I am providing correct password.
app.post('/login', (req, res) => {
const username = req.body.username;
const password = req.body.password;
db.query('SELECT * FROM dataa WHERE username = ?',[username], function (error, rows, fields) {
if (error) {
// console.log("error ocurred",error);
res.send({
"code":400,
"failed":"error ocurred"
})
}else{
// console.log('The solution is: ', results);
if(rows.length >0){
console.log(bcrypt.compareSync(password, rows[0].password));
if(bcrypt.compareSync(password, rows[0].password)){
res.send({
"code":200,
"success":"login sucessfull"
});
}
else{
res.send({
"code":204,
"success":"Email and password does not match"
});
}
}
else{
res.send({
"code":204,
"success":"Email does not exits"
});
}
}
});
})
mysql node.js
How do you persist user(and password)? Do you store raw password or hashed?
– slesh
Jan 1 at 13:23
If you did store the password as plain text you have to hash the password usingbcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) { // Store hash in your password DB. });
If that is not the case make sure your password is not padded with whitespace, trim the password first.
– Cocest
Jan 1 at 13:28
I have hassed password in database.
– user10849358
Jan 1 at 13:30
Not a valid BCrypt hash. giving such error.
– user10849358
Jan 1 at 13:41
@user10849358 Do you hash the password using the same bcrypt? If not, use bcrypt instead.
– Cocest
Jan 1 at 13:47
|
show 1 more comment
My input password and database password are same then also function is returning false. Here compare method is not working properly.I am getting false in return everytime while I am providing correct password.
app.post('/login', (req, res) => {
const username = req.body.username;
const password = req.body.password;
db.query('SELECT * FROM dataa WHERE username = ?',[username], function (error, rows, fields) {
if (error) {
// console.log("error ocurred",error);
res.send({
"code":400,
"failed":"error ocurred"
})
}else{
// console.log('The solution is: ', results);
if(rows.length >0){
console.log(bcrypt.compareSync(password, rows[0].password));
if(bcrypt.compareSync(password, rows[0].password)){
res.send({
"code":200,
"success":"login sucessfull"
});
}
else{
res.send({
"code":204,
"success":"Email and password does not match"
});
}
}
else{
res.send({
"code":204,
"success":"Email does not exits"
});
}
}
});
})
mysql node.js
My input password and database password are same then also function is returning false. Here compare method is not working properly.I am getting false in return everytime while I am providing correct password.
app.post('/login', (req, res) => {
const username = req.body.username;
const password = req.body.password;
db.query('SELECT * FROM dataa WHERE username = ?',[username], function (error, rows, fields) {
if (error) {
// console.log("error ocurred",error);
res.send({
"code":400,
"failed":"error ocurred"
})
}else{
// console.log('The solution is: ', results);
if(rows.length >0){
console.log(bcrypt.compareSync(password, rows[0].password));
if(bcrypt.compareSync(password, rows[0].password)){
res.send({
"code":200,
"success":"login sucessfull"
});
}
else{
res.send({
"code":204,
"success":"Email and password does not match"
});
}
}
else{
res.send({
"code":204,
"success":"Email does not exits"
});
}
}
});
})
mysql node.js
mysql node.js
asked Jan 1 at 13:18
user10849358user10849358
12
12
How do you persist user(and password)? Do you store raw password or hashed?
– slesh
Jan 1 at 13:23
If you did store the password as plain text you have to hash the password usingbcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) { // Store hash in your password DB. });
If that is not the case make sure your password is not padded with whitespace, trim the password first.
– Cocest
Jan 1 at 13:28
I have hassed password in database.
– user10849358
Jan 1 at 13:30
Not a valid BCrypt hash. giving such error.
– user10849358
Jan 1 at 13:41
@user10849358 Do you hash the password using the same bcrypt? If not, use bcrypt instead.
– Cocest
Jan 1 at 13:47
|
show 1 more comment
How do you persist user(and password)? Do you store raw password or hashed?
– slesh
Jan 1 at 13:23
If you did store the password as plain text you have to hash the password usingbcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) { // Store hash in your password DB. });
If that is not the case make sure your password is not padded with whitespace, trim the password first.
– Cocest
Jan 1 at 13:28
I have hassed password in database.
– user10849358
Jan 1 at 13:30
Not a valid BCrypt hash. giving such error.
– user10849358
Jan 1 at 13:41
@user10849358 Do you hash the password using the same bcrypt? If not, use bcrypt instead.
– Cocest
Jan 1 at 13:47
How do you persist user(and password)? Do you store raw password or hashed?
– slesh
Jan 1 at 13:23
How do you persist user(and password)? Do you store raw password or hashed?
– slesh
Jan 1 at 13:23
If you did store the password as plain text you have to hash the password using
bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) { // Store hash in your password DB. });
If that is not the case make sure your password is not padded with whitespace, trim the password first.– Cocest
Jan 1 at 13:28
If you did store the password as plain text you have to hash the password using
bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) { // Store hash in your password DB. });
If that is not the case make sure your password is not padded with whitespace, trim the password first.– Cocest
Jan 1 at 13:28
I have hassed password in database.
– user10849358
Jan 1 at 13:30
I have hassed password in database.
– user10849358
Jan 1 at 13:30
Not a valid BCrypt hash. giving such error.
– user10849358
Jan 1 at 13:41
Not a valid BCrypt hash. giving such error.
– user10849358
Jan 1 at 13:41
@user10849358 Do you hash the password using the same bcrypt? If not, use bcrypt instead.
– Cocest
Jan 1 at 13:47
@user10849358 Do you hash the password using the same bcrypt? If not, use bcrypt instead.
– Cocest
Jan 1 at 13:47
|
show 1 more comment
1 Answer
1
active
oldest
votes
You might be having more than one username in your database which match it up with the username your are giving so it will try and match it with the first one but the password would be a different one ..
I have a single username in database.
– user10849358
Jan 1 at 17:42
Is your password properly hashed ?
– THEWOLF
Jan 2 at 7:12
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f53995765%2fnot-able-to-compare-my-database-password-and-input-field-password%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
You might be having more than one username in your database which match it up with the username your are giving so it will try and match it with the first one but the password would be a different one ..
I have a single username in database.
– user10849358
Jan 1 at 17:42
Is your password properly hashed ?
– THEWOLF
Jan 2 at 7:12
add a comment |
You might be having more than one username in your database which match it up with the username your are giving so it will try and match it with the first one but the password would be a different one ..
I have a single username in database.
– user10849358
Jan 1 at 17:42
Is your password properly hashed ?
– THEWOLF
Jan 2 at 7:12
add a comment |
You might be having more than one username in your database which match it up with the username your are giving so it will try and match it with the first one but the password would be a different one ..
You might be having more than one username in your database which match it up with the username your are giving so it will try and match it with the first one but the password would be a different one ..
answered Jan 1 at 13:45
THEWOLFTHEWOLF
8251213
8251213
I have a single username in database.
– user10849358
Jan 1 at 17:42
Is your password properly hashed ?
– THEWOLF
Jan 2 at 7:12
add a comment |
I have a single username in database.
– user10849358
Jan 1 at 17:42
Is your password properly hashed ?
– THEWOLF
Jan 2 at 7:12
I have a single username in database.
– user10849358
Jan 1 at 17:42
I have a single username in database.
– user10849358
Jan 1 at 17:42
Is your password properly hashed ?
– THEWOLF
Jan 2 at 7:12
Is your password properly hashed ?
– THEWOLF
Jan 2 at 7:12
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.
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%2f53995765%2fnot-able-to-compare-my-database-password-and-input-field-password%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
How do you persist user(and password)? Do you store raw password or hashed?
– slesh
Jan 1 at 13:23
If you did store the password as plain text you have to hash the password using
bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) { // Store hash in your password DB. });
If that is not the case make sure your password is not padded with whitespace, trim the password first.– Cocest
Jan 1 at 13:28
I have hassed password in database.
– user10849358
Jan 1 at 13:30
Not a valid BCrypt hash. giving such error.
– user10849358
Jan 1 at 13:41
@user10849358 Do you hash the password using the same bcrypt? If not, use bcrypt instead.
– Cocest
Jan 1 at 13:47