Not able to compare my database password and input field password












0















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"
});
}
}
});


})









share|improve this question























  • 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
















0















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"
});
}
}
});


})









share|improve this question























  • 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














0












0








0








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"
});
}
}
});


})









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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



















  • 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

















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












1 Answer
1






active

oldest

votes


















0














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 ..






share|improve this answer
























  • I have a single username in database.

    – user10849358
    Jan 1 at 17:42











  • Is your password properly hashed ?

    – THEWOLF
    Jan 2 at 7:12













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
});


}
});














draft saved

draft discarded


















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









0














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 ..






share|improve this answer
























  • I have a single username in database.

    – user10849358
    Jan 1 at 17:42











  • Is your password properly hashed ?

    – THEWOLF
    Jan 2 at 7:12


















0














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 ..






share|improve this answer
























  • I have a single username in database.

    – user10849358
    Jan 1 at 17:42











  • Is your password properly hashed ?

    – THEWOLF
    Jan 2 at 7:12
















0












0








0







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 ..






share|improve this answer













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 ..







share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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






















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.




draft saved


draft discarded














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





















































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

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

ts Property 'filter' does not exist on type '{}'

mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window