When registering as a member, the password is hash encrypted and stored in the db. And when you log in, compare the "saved password value" with the encrypted input value. But the hash value does not match..
Please tell me the answer..
How can I encrypt and store my password and authenticate it?
[join]
[login]
code
[
{
"id": "786b1874642b9820",
"type": "bcrypt",
"z": "f24308a3b5ba3065",
"name": "Hash",
"action": "encrypt",
"field": "payload",
"hash": "payload.Password",
"target": "hashedPassword",
"assignment": "assign",
"match": "match",
"outputs": 1,
"rounds": 10,
"x": 970,
"y": 940,
"wires": [
[
"72386f8c52890b0f"
]
]
},
{
"id": "72a0d93bd2ecb457",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "Initialize Login Global variable",
"func": "var loginUserID = \"\"; // ์ฌ์ฉ์ ID ์ ์ญ ๋ณ์ ์ด๊ธฐํ\nvar loginPassword = \"\"; // ์ฌ์ฉ์ PW ์ ์ญ ๋ณ์ ์ด๊ธฐํ\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1690,
"y": 160,
"wires": [
[
"a78dda5c7824101b"
]
]
},
{
"id": "81e7bd05ae129113",
"type": "ui_form",
"z": "f24308a3b5ba3065",
"name": "",
"label": "",
"group": "c7079967a92c6224",
"order": 2,
"width": 8,
"height": 1,
"options": [
{
"label": "ID",
"value": "UserID",
"type": "text",
"required": true,
"rows": null
},
{
"label": "P/W",
"value": "Password",
"type": "password",
"required": true,
"rows": null
}
],
"formValue": {
"UserID": "",
"Password": ""
},
"payload": "",
"submit": "Log In",
"cancel": "",
"topic": "topic",
"topicType": "msg",
"splitLayout": "",
"className": "login-form",
"x": 270,
"y": 160,
"wires": [
[
"d69667f70acbc5a9"
]
]
},
{
"id": "d69667f70acbc5a9",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "์
๋ ฅํ value์ ๋ํด set global",
"func": "if (msg.payload.UserID !== \"\" && msg.payload.Password !== \"\") {\n global.set(\"loginUserID\", msg.payload.UserID);\n global.set(\"loginPassword\", msg.payload.Password);\n}\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 510,
"y": 160,
"wires": [
[
"b3578c929d7d92d6"
]
]
},
{
"id": "b3578c929d7d92d6",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "์
๋ ฅํ Username์ด mySQL์ ์กด์ฌํ๋์ง ํ์ธ",
"func": "var id = global.get(\"loginUserID\");\nvar password = global.get(\"loginPassword\");\nmsg.topic = \"SELECT * FROM users WHERE userID = ?\";\n\nif (id && password) {\n msg.payload = [id];\n} else {\n // ID๋ Password๊ฐ ์๋ ๊ฒฝ์ฐ, ๋น ๋ฐฐ์ด ๋ฐํ\n msg.payload = [];\n}\n//msg.topic = \"SELECT * FROM users WHERE userName = ? AND password = ?\";\n//msg.payload = [id];\nreturn msg;\n\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 640,
"y": 120,
"wires": [
[
"2c718276cb0103ab",
"e27adc0465a38210"
]
]
},
{
"id": "2c718276cb0103ab",
"type": "mysql",
"z": "f24308a3b5ba3065",
"mydb": "23139c6750c1e4b8",
"name": "",
"x": 790,
"y": 160,
"wires": [
[
"c4662fdb622dc1cb"
]
]
},
{
"id": "c4662fdb622dc1cb",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "userID Authentication",
"func": "/*if(msg.payload!=null){\n msg.payload=\"Login Success\";\n}else {\n msg.payload =\"Login Failed\";\n}\nreturn msg;*/\n// ์ฌ์ฉ์๋ฅผ ์ธ์ฆํ๋ ํจ์\nvar loginUserID = global.get(\"loginUserID\");\nvar loginPassword = global.get(\"loginPassword\");\n\nif (msg.payload.length > 0) {\n msg.payload=msg.payload[0].password;\n} else {\n msg.payload = \"1\";\n}\n\n\nreturn msg;\n\n\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 980,
"y": 160,
"wires": [
[
"30f5aad881941c2e"
]
]
},
{
"id": "e27adc0465a38210",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "์
๋ ฅํ ํจ์ค์๋ ๊ฐ ํด์์ํธํ",
"func": "var password = global.get(\"loginPassword\");\nmsg.payload = password;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1010,
"y": 120,
"wires": [
[
"hashPasswordNode"
]
]
},
{
"id": "30f5aad881941c2e",
"type": "switch",
"z": "f24308a3b5ba3065",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1170,
"y": 160,
"wires": [
[
"b64f9f2565bc65df"
],
[
"0726c4f7cddcd99a"
]
]
},
{
"id": "hashPasswordNode",
"type": "bcrypt",
"z": "f24308a3b5ba3065",
"name": "Hash",
"action": "encrypt",
"field": "payload",
"hash": "payload",
"target": "hashedPassword",
"assignment": "assign",
"match": "match",
"outputs": 1,
"rounds": 10,
"x": 1250,
"y": 120,
"wires": [
[
"2946c034f0db4cfe",
"0726c4f7cddcd99a"
]
]
},
{
"id": "0726c4f7cddcd99a",
"type": "bcrypt",
"z": "f24308a3b5ba3065",
"name": "Hash",
"action": "verify",
"field": "payload",
"hash": "hashedPassword",
"target": "payload",
"assignment": "replace",
"match": "match",
"outputs": 1,
"rounds": 10,
"x": 1390,
"y": 120,
"wires": [
[
"a53065b1e6b61d3e",
"ac8b9b82257b3848"
]
]
},
{
"id": "b64f9f2565bc65df",
"type": "change",
"z": "f24308a3b5ba3065",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "'<font color=\"red\">Login Failed: Invalid Password.</font>'",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1440,
"y": 160,
"wires": [
[
"72a0d93bd2ecb457"
]
]
},
{
"id": "ac8b9b82257b3848",
"type": "change",
"z": "f24308a3b5ba3065",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{ group: { show: [\"Dashboard_Database\", \"Dashboard_Button\"], hide : [\"Dashboard_LogIn\"] } }",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1580,
"y": 120,
"wires": [
[
"98c6069a7cc33299"
]
]
},
{
"id": "98c6069a7cc33299",
"type": "ui_ui_control",
"z": "f24308a3b5ba3065",
"name": "Disable Sign In Tab",
"events": "all",
"x": 1790,
"y": 120,
"wires": [
[]
]
},
{
"id": "a78dda5c7824101b",
"type": "ui_text",
"z": "f24308a3b5ba3065",
"group": "c7079967a92c6224",
"order": 4,
"width": 8,
"height": 1,
"name": "Show if Invaild Input Value",
"label": "",
"format": "{{msg.payload}}",
"layout": "row-left",
"className": "",
"style": false,
"font": "",
"fontSize": 16,
"color": "#000000",
"x": 2040,
"y": 160,
"wires": []
},
{
"id": "623b821c018a0373",
"type": "inject",
"z": "f24308a3b5ba3065",
"name": "์ด๊ธฐํ",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "str",
"x": 2000,
"y": 120,
"wires": [
[
"a78dda5c7824101b"
]
]
},
{
"id": "58cd1a00cee12c78",
"type": "ui_form",
"z": "f24308a3b5ba3065",
"name": "",
"label": "",
"group": "b8c8837d084d2116",
"order": 2,
"width": 8,
"height": 1,
"options": [
{
"label": "Please Enter Username",
"value": "Username",
"type": "text",
"required": true,
"rows": null
},
{
"label": "Please Enter UserID",
"value": "UserID",
"type": "text",
"required": true,
"rows": null
},
{
"label": "Please Enter Password",
"value": "Password",
"type": "password",
"required": true,
"rows": null
},
{
"label": "Please Enter Email",
"value": "Email",
"type": "email",
"required": true,
"rows": null
}
],
"formValue": {
"Username": "",
"UserID": "",
"Password": "",
"Email": ""
},
"payload": "",
"submit": "Join",
"cancel": "cancel",
"topic": "topic",
"topicType": "msg",
"splitLayout": "",
"className": "join-form",
"x": 270,
"y": 800,
"wires": [
[
"7ba1d061485645a8"
]
]
},
{
"id": "7ba1d061485645a8",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "์
๋ ฅํ value์ ๋ํด set global",
"func": "if (msg.payload.Username !== \"\" &&msg.payload.UserID !== \"\" && msg.payload.Password !== \"\" &&msg.payload.Email !== \"\") {\n global.set(\"joinUsername\", msg.payload.Username);\n global.set(\"joinUserID\",msg.payload.UserID);\n global.set(\"joinPassword\", msg.payload.Password);\n global.set(\"joinEmail\",msg.payload.Email);\n}\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 490,
"y": 800,
"wires": [
[
"ff4850f5279f68ef"
]
]
},
{
"id": "ff4850f5279f68ef",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "์
๋ ฅํ Username์ด mySQL์ ์กด์ฌํ๋์ง ํ์ธ",
"func": "var userName = global.get(\"joinUsername\");\nvar id = global.get(\"joinUserID\");\nvar password = global.get(\"joinPassword\");\nvar email = global.get(\"joinEmail\");\n\nmsg.topic = \"SELECT * FROM users WHERE UserID = \\\"?\\\" OR Email = \\\"?\\\"\";\nif (id || email) {\n msg.payload = [id, email];\n} else {\n // UserID๋ Email์ด ์๋ ๊ฒฝ์ฐ, ๋น ๋ฐฐ์ด ๋ฐํ\n msg.payload = [];\n}\n\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 600,
"y": 760,
"wires": [
[
"5bd4f7604325dd40"
]
]
},
{
"id": "5bd4f7604325dd40",
"type": "mysql",
"z": "f24308a3b5ba3065",
"mydb": "23139c6750c1e4b8",
"name": "",
"x": 730,
"y": 800,
"wires": [
[
"59a3ca97cb034e62"
]
]
},
{
"id": "59a3ca97cb034e62",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "์
๋ ฅํ ๋ด์ฉ์ด mySQL์ ์กด์ฌํ๋์ง ํ์ธ",
"func": "var userName = global.get(\"joinUsername\");\nvar id = global.get(\"joinUserID\");\nvar password = global.get(\"joinPassword\");\nvar email = global.get(\"joinEmail\");\n\n\nif (msg.payload.length > 0) {\n var registeredID = msg.payload[0].userID;\n var registeredEmail = msg.payload[0].email;\n if (registeredID === id) {\n msg.payload = \"1\";\n\n //msg.payload = \"์ด๋ฏธ ์กด์ฌํ๋ ์์ด๋์
๋๋ค.\";\n } else if (registeredEmail === email) {\n msg.payload = \"2\";\n //msg.payload = \"์ด๋ฏธ ๋ฑ๋ก๋ ์ฌ์ฉ์์
๋๋ค.\";\n \n }\n} else {\n msg.payload = \"0\";\n}\nreturn msg;\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 960,
"y": 800,
"wires": [
[
"6121df8c5420c58a"
]
]
},
{
"id": "6121df8c5420c58a",
"type": "switch",
"z": "f24308a3b5ba3065",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "str"
},
{
"t": "eq",
"v": "2",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 850,
"y": 880,
"wires": [
[
"a74809473229c054"
],
[
"dfef7de1a0fb0bf1"
],
[
"7376212370ea6e80"
]
]
},
{
"id": "7376212370ea6e80",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "hash password",
"func": "var password = global.get(\"joinPassword\");\nmsg.payload=password;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 800,
"y": 940,
"wires": [
[
"786b1874642b9820"
]
]
},
{
"id": "a74809473229c054",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "ID ์ค๋ณต",
"func": "var id = global.get(\"joinUserID\");\nvar string = \"\";\nstring = '<font color=\"red\" style=\"font-size: 20px;\"> [' + id + '] is already exists. Please enter a different ID.</font>';\nmsg.payload = string;\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1060,
"y": 860,
"wires": [
[
"0a845d748cfc3b6c"
]
]
},
{
"id": "dfef7de1a0fb0bf1",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "Email ์ค๋ณต",
"func": "var email = global.get(\"joinEmail\");\nvar string = \"\";\nstring ='<font color=\"red\" style=\"font-size: 20px;\"> ['+email+'] is already registered E-mail.</font>';\nmsg.payload = string;\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1070,
"y": 900,
"wires": [
[
"0a845d748cfc3b6c"
]
]
},
{
"id": "72386f8c52890b0f",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "Register user on MySQL",
"func": "var userName = global.get(\"joinUsername\");\nvar id = global.get(\"joinUserID\");\nvar password = global.get(\"joinPassword\");\nvar email = global.get(\"joinEmail\");\nvar hash = msg.hashedPassword;\n// mysql์ ๋ฑ๋ก\nmsg.topic = \"INSERT INTO users (userName, userID, password, email) VALUES (?, ?, ?, ?)\";\n\nmsg.payload = [userName, id, hash, email];\n\n\n\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1170,
"y": 940,
"wires": [
[
"09f0ce1c8d07b0d8"
]
]
},
{
"id": "09f0ce1c8d07b0d8",
"type": "mysql",
"z": "f24308a3b5ba3065",
"mydb": "23139c6750c1e4b8",
"name": "",
"x": 1130,
"y": 980,
"wires": [
[
"730ef2daeebebd99"
]
]
},
{
"id": "730ef2daeebebd99",
"type": "change",
"z": "f24308a3b5ba3065",
"name": "Go to Sign In",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"group\":{\"show\":[\"Dashboard_LogIn\"],\"hide\":[\"Dashboard_Database\",\"Dashboard_Button\",\"Dashboard_[Device1]Monitor\",\"Dashboard_[Device1]Control\",\"Dashboard_[Device2]Monitor\",\"Dashboard_[Device2]Control\",\"Dashboard_SignUp\"]}}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1290,
"y": 980,
"wires": [
[
"601226042819841a"
]
]
},
{
"id": "0a845d748cfc3b6c",
"type": "function",
"z": "f24308a3b5ba3065",
"name": "Initialize Email Global variable",
"func": "var joinUsername = \"\"; // ์ฌ์ฉ์ ์ด๋ฆ ์ ์ญ ๋ณ์ ์ด๊ธฐํ\nvar joinUserID = \"\"; // ์ฌ์ฉ์ ID ์ ์ญ ๋ณ์ ์ด๊ธฐํ\nvar joinPassword = \"\"; // ๋น๋ฐ๋ฒํธ ์ ์ญ ๋ณ์ ์ด๊ธฐํ\nvar joinEmail = \"\"; // ์ด๋ฉ์ผ ์ ์ญ ๋ณ์ ์ด๊ธฐํ\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1390,
"y": 880,
"wires": [
[
"a0b5ef099d3875ee"
]
]
},
{
"id": "a0b5ef099d3875ee",
"type": "ui_text",
"z": "f24308a3b5ba3065",
"group": "b8c8837d084d2116",
"order": 4,
"width": 8,
"height": 1,
"name": "Show if userID or e-mail already taken",
"label": "",
"format": "{{msg.payload}}",
"layout": "row-left",
"className": "",
"style": false,
"font": "",
"fontSize": 16,
"color": "#000000",
"x": 1730,
"y": 880,
"wires": []
},
{
"id": "601226042819841a",
"type": "ui_ui_control",
"z": "f24308a3b5ba3065",
"name": "Go to Dashboard",
"events": "all",
"x": 1490,
"y": 980,
"wires": [
[]
]
},
{
"id": "c7079967a92c6224",
"type": "ui_group",
"name": "LogIn",
"tab": "3ee156d8dba4fea3",
"order": 1,
"disp": false,
"width": "8",
"collapse": false,
"className": "loginForm"
},
{
"id": "23139c6750c1e4b8",
"type": "MySQLdatabase",
"name": "",
"host": "127.0.0.1",
"port": "3306",
"db": "project",
"tz": "",
"charset": "UTF8"
},
{
"id": "b8c8837d084d2116",
"type": "ui_group",
"name": "SignUp",
"tab": "3ee156d8dba4fea3",
"order": 4,
"disp": false,
"width": "8",
"collapse": false,
"className": "joinForm"
},
{
"id": "3ee156d8dba4fea3",
"type": "ui_tab",
"name": "Dashboard",
"icon": "dashboard",
"order": 6,
"disabled": false,
"hidden": false
}
]