[login/join] password bcrypt with mysql

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

In your Register user on MySQL function node you are storing the 'hash' in the column 'payload'

What you want to do is store the hash in the database then when a user attempts to login, you retrieve the hash from the database and pass the hash and entered password to a bcrypt that is set to compare the two.

Here is a simple flow demonstrating this using flow contest in place of a database

[{"id":"06396cae4619e2e6","type":"inject","z":"f6e99a8bfb0b23bf","name":"save password","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"mypassword","payloadType":"str","x":180,"y":80,"wires":[["637e702b34a279c7"]]},{"id":"637e702b34a279c7","type":"bcrypt","z":"f6e99a8bfb0b23bf","name":"","action":"encrypt","field":"payload","hash":"payload","target":"payload","assignment":"replace","match":"match","outputs":1,"rounds":10,"x":410,"y":80,"wires":[["feb80f9d8ec082e4"]]},{"id":"381bebed2ee30b52","type":"bcrypt","z":"f6e99a8bfb0b23bf","name":"","action":"verify","field":"payload","hash":"hash","target":"payload","assignment":"replace","match":"match","outputs":1,"rounds":10,"x":420,"y":200,"wires":[["55008d7dcf7e608f"]]},{"id":"feb80f9d8ec082e4","type":"change","z":"f6e99a8bfb0b23bf","name":"","rules":[{"t":"set","p":"hash","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":80,"wires":[["a928f0eaaf6765e1"]]},{"id":"a928f0eaaf6765e1","type":"debug","z":"f6e99a8bfb0b23bf","name":"debug 3398","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":80,"wires":[]},{"id":"af9c0df92887d987","type":"inject","z":"f6e99a8bfb0b23bf","name":"valid login attempt","props":[{"p":"payload"},{"p":"hash","v":"hash","vt":"flow"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"mypassword","payloadType":"str","x":190,"y":160,"wires":[["381bebed2ee30b52"]]},{"id":"55008d7dcf7e608f","type":"debug","z":"f6e99a8bfb0b23bf","name":"debug 3399","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"match","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":200,"wires":[]},{"id":"0f3f93bb83b4e159","type":"inject","z":"f6e99a8bfb0b23bf","name":"Hacking login attempt","props":[{"p":"payload"},{"p":"hash","v":"hash","vt":"flow"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"123456","payloadType":"str","x":200,"y":240,"wires":[["381bebed2ee30b52"]]}]
1 Like

First of all, thank you for your help.
But I still need help..Please review my code..
In "flow.hash", you put the password value stored in db. After that, when you log in, you get the value through get.flow ('hash') and compare it with the password you entered in the login form, but the match value continues to be false. Where is the problem?

[
    {
        "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": "e27adc0465a38210",
        "type": "function",
        "z": "f24308a3b5ba3065",
        "name": "์ž…๋ ฅํ•œ ํŒจ์Šค์›Œ๋“œ ๊ฐ’ ํ•ด์‹œ์•”ํ˜ธํ™” ๋น„๊ต",
        "func": "var password = global.get(\"loginPassword\");\nmsg.payload = password;\nvar hashValue = flow.get('hash');\nmsg.hash = hashValue; \nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1030,
        "y": 120,
        "wires": [
            [
                "589f9a78e7339d88"
            ]
        ]
    },
    {
        "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": "2c718276cb0103ab",
        "type": "mysql",
        "z": "f24308a3b5ba3065",
        "mydb": "23139c6750c1e4b8",
        "name": "",
        "x": 790,
        "y": 160,
        "wires": [
            [
                "c4662fdb622dc1cb"
            ]
        ]
    },
    {
        "id": "589f9a78e7339d88",
        "type": "bcrypt",
        "z": "f24308a3b5ba3065",
        "name": "",
        "action": "verify",
        "field": "payload",
        "hash": "hash",
        "target": "payload",
        "assignment": "replace",
        "match": "match",
        "outputs": 1,
        "rounds": 10,
        "x": 1280,
        "y": 120,
        "wires": [
            [
                "3ce9819d63efe098"
            ]
        ]
    },
    {
        "id": "3ce9819d63efe098",
        "type": "debug",
        "z": "f24308a3b5ba3065",
        "name": "debug 3401",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1450,
        "y": 120,
        "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": "3ee156d8dba4fea3",
        "type": "ui_tab",
        "name": "Dashboard",
        "icon": "dashboard",
        "order": 6,
        "disabled": false,
        "hidden": false
    }
]
[
    {
        "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": 580,
        "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": 580,
        "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": 540,
        "wires": [
            [
                "5bd4f7604325dd40"
            ]
        ]
    },
    {
        "id": "5bd4f7604325dd40",
        "type": "mysql",
        "z": "f24308a3b5ba3065",
        "mydb": "23139c6750c1e4b8",
        "name": "",
        "x": 730,
        "y": 580,
        "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": 580,
        "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": 660,
        "wires": [
            [
                "a74809473229c054"
            ],
            [
                "dfef7de1a0fb0bf1"
            ],
            [
                "55d3bc520aad4dce"
            ]
        ]
    },
    {
        "id": "55d3bc520aad4dce",
        "type": "bcrypt",
        "z": "f24308a3b5ba3065",
        "name": "",
        "action": "encrypt",
        "field": "payload",
        "hash": "payload",
        "target": "hashedPassword",
        "assignment": "assign",
        "match": "match",
        "outputs": 1,
        "rounds": 10,
        "x": 930,
        "y": 720,
        "wires": [
            [
                "72386f8c52890b0f"
            ]
        ]
    },
    {
        "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": 640,
        "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": 680,
        "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": 1150,
        "y": 720,
        "wires": [
            [
                "09f0ce1c8d07b0d8",
                "977ba86dfac2fcdb"
            ]
        ]
    },
    {
        "id": "09f0ce1c8d07b0d8",
        "type": "mysql",
        "z": "f24308a3b5ba3065",
        "mydb": "23139c6750c1e4b8",
        "name": "",
        "x": 1130,
        "y": 760,
        "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": 760,
        "wires": [
            [
                "601226042819841a"
            ]
        ]
    },
    {
        "id": "977ba86dfac2fcdb",
        "type": "change",
        "z": "f24308a3b5ba3065",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "hash",
                "pt": "flow",
                "to": "hashedPassword",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1410,
        "y": 720,
        "wires": [
            [
                "b99f05ccc1d87383"
            ]
        ]
    },
    {
        "id": "b99f05ccc1d87383",
        "type": "debug",
        "z": "f24308a3b5ba3065",
        "name": "debug 3400",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1600,
        "y": 720,
        "wires": []
    },
    {
        "id": "601226042819841a",
        "type": "ui_ui_control",
        "z": "f24308a3b5ba3065",
        "name": "Go to Dashboard",
        "events": "all",
        "x": 1490,
        "y": 760,
        "wires": [
            []
        ]
    },
    {
        "id": "b8c8837d084d2116",
        "type": "ui_group",
        "name": "SignUp",
        "tab": "3ee156d8dba4fea3",
        "order": 4,
        "disp": false,
        "width": "8",
        "collapse": false,
        "className": "joinForm"
    },
    {
        "id": "23139c6750c1e4b8",
        "type": "MySQLdatabase",
        "name": "",
        "host": "127.0.0.1",
        "port": "3306",
        "db": "project",
        "tz": "",
        "charset": "UTF8"
    },
    {
        "id": "3ee156d8dba4fea3",
        "type": "ui_tab",
        "name": "Dashboard",
        "icon": "dashboard",
        "order": 6,
        "disabled": false,
        "hidden": false
    }
]

I cannot import that code I'm afraid.

  1. when you export two flows separately, paste each one with three back-tics before and after teach export. By posting them both in the same set of back-ticks they are not importable without going thru the code to find where the second export begins and ends.

  2. you ask:
    In "flow.hash", you put the password value stored in db.
    I did that because I do not have the schema for your database so I used a flow context variable to get past that issue.

  3. Why are you still storing the hash in the password column of the database?

  4. add a debug node (set to display the complete msg object) to:
    A) the output of the ์ž…๋ ฅํ•œ ๋‚ด์šฉ์ด mySQL์— ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ function node
    B) to the 'otherwise' output of the switch following it
    C) the output of the hash node

  5. What is the value you are hashing?

I'm sorry. I'll send it again.

[
    {
        "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": "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": "23356ad7ea7fe4f3",
        "type": "ui_button",
        "z": "f24308a3b5ba3065",
        "name": "",
        "group": "c7079967a92c6224",
        "order": 3,
        "width": 8,
        "height": 1,
        "passthru": false,
        "label": "Sign Up",
        "tooltip": "",
        "color": "",
        "bgcolor": "#FFB703",
        "className": "Joinbtn",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "topic",
        "topicType": "msg",
        "x": 280,
        "y": 300,
        "wires": [
            [
                "6949579def2958b9"
            ]
        ]
    },
    {
        "id": "6949579def2958b9",
        "type": "change",
        "z": "f24308a3b5ba3065",
        "name": "Go to Join",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"group\":{\"show\":[\"Dashboard_SignUp\"],\"hide\":[\"Dashboard_Database\",\"Dashboard_Button\",\"Dashboard_[Device1]Monitor\",\"Dashboard_[Device1]Control\",\"Dashboard_[Device2]Monitor\",\"Dashboard_[Device2]Control\",\"Dashboard_LogIn\"]}}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 450,
        "y": 300,
        "wires": [
            [
                "8aa523cf01ecb715"
            ]
        ]
    },
    {
        "id": "8aa523cf01ecb715",
        "type": "ui_ui_control",
        "z": "f24308a3b5ba3065",
        "name": "Go to Dashboard",
        "events": "all",
        "x": 650,
        "y": 300,
        "wires": [
            []
        ]
    },
    {
        "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": 400,
        "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": 400,
        "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": 360,
        "wires": [
            [
                "5bd4f7604325dd40"
            ]
        ]
    },
    {
        "id": "5bd4f7604325dd40",
        "type": "mysql",
        "z": "f24308a3b5ba3065",
        "mydb": "23139c6750c1e4b8",
        "name": "",
        "x": 730,
        "y": 400,
        "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": 400,
        "wires": [
            [
                "6121df8c5420c58a"
            ]
        ]
    },
    {
        "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": 480,
        "wires": []
    },
    {
        "id": "fab9abbf58e69d61",
        "type": "inject",
        "z": "f24308a3b5ba3065",
        "name": "์ดˆ๊ธฐํ™”",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 1660,
        "y": 440,
        "wires": [
            [
                "a0b5ef099d3875ee"
            ]
        ]
    },
    {
        "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": 480,
        "wires": [
            [
                "a74809473229c054"
            ],
            [
                "dfef7de1a0fb0bf1"
            ],
            [
                "55d3bc520aad4dce"
            ]
        ]
    },
    {
        "id": "09f0ce1c8d07b0d8",
        "type": "mysql",
        "z": "f24308a3b5ba3065",
        "mydb": "23139c6750c1e4b8",
        "name": "",
        "x": 1130,
        "y": 580,
        "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": 580,
        "wires": [
            [
                "601226042819841a"
            ]
        ]
    },
    {
        "id": "601226042819841a",
        "type": "ui_ui_control",
        "z": "f24308a3b5ba3065",
        "name": "Go to Dashboard",
        "events": "all",
        "x": 1490,
        "y": 580,
        "wires": [
            []
        ]
    },
    {
        "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": "e2c6073273e8a1f3",
        "type": "inject",
        "z": "f24308a3b5ba3065",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "str",
        "x": 290,
        "y": 40,
        "wires": [
            [
                "e6300c7820f61cbd"
            ]
        ]
    },
    {
        "id": "e6300c7820f61cbd",
        "type": "change",
        "z": "f24308a3b5ba3065",
        "name": "Go to Database",
        "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": 480,
        "y": 40,
        "wires": [
            [
                "d30fc3e45196d4d4"
            ]
        ]
    },
    {
        "id": "d30fc3e45196d4d4",
        "type": "ui_ui_control",
        "z": "f24308a3b5ba3065",
        "name": "",
        "events": "all",
        "x": 700,
        "y": 40,
        "wires": [
            []
        ]
    },
    {
        "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"
            ]
        ]
    },
    {
        "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": 1150,
        "y": 540,
        "wires": [
            [
                "09f0ce1c8d07b0d8",
                "977ba86dfac2fcdb"
            ]
        ]
    },
    {
        "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": 460,
        "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": 500,
        "wires": [
            [
                "0a845d748cfc3b6c"
            ]
        ]
    },
    {
        "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": 480,
        "wires": [
            [
                "a0b5ef099d3875ee"
            ]
        ]
    },
    {
        "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": 1190,
        "y": 160,
        "wires": [
            [
                "b64f9f2565bc65df"
            ],
            [
                "e27adc0465a38210"
            ]
        ]
    },
    {
        "id": "98c6069a7cc33299",
        "type": "ui_ui_control",
        "z": "f24308a3b5ba3065",
        "name": "Disable Sign In Tab",
        "events": "all",
        "x": 2410,
        "y": 300,
        "wires": [
            []
        ]
    },
    {
        "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": 1830,
        "y": 160,
        "wires": [
            [
                "a78dda5c7824101b"
            ]
        ]
    },
    {
        "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": 2280,
        "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": 2020,
        "y": 100,
        "wires": [
            [
                "a78dda5c7824101b"
            ]
        ]
    },
    {
        "id": "e27adc0465a38210",
        "type": "function",
        "z": "f24308a3b5ba3065",
        "name": "์ž…๋ ฅํ•œ ํŒจ์Šค์›Œ๋“œ ๊ฐ’ ํ•ด์‹œ์•”ํ˜ธํ™” ๋น„๊ต",
        "func": "var password = global.get(\"loginPassword\");\nmsg.payload = password;\nvar hashValue = flow.get('hash');\nmsg.hash = hashValue; \nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1330,
        "y": 240,
        "wires": [
            [
                "589f9a78e7339d88"
            ]
        ]
    },
    {
        "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": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2220,
        "y": 300,
        "wires": [
            [
                "98c6069a7cc33299"
            ]
        ]
    },
    {
        "id": "b64f9f2565bc65df",
        "type": "change",
        "z": "f24308a3b5ba3065",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "<font color=\"red\">Login Failed: User Not Found.</font>",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1420,
        "y": 160,
        "wires": [
            [
                "72a0d93bd2ecb457"
            ]
        ]
    },
    {
        "id": "36db41dafe050e0d",
        "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": 2220,
        "y": 240,
        "wires": [
            [
                "72a0d93bd2ecb457"
            ]
        ]
    },
    {
        "id": "97cb53f549d8ebd0",
        "type": "function",
        "z": "f24308a3b5ba3065",
        "name": "compare password",
        "func": "if(msg.match == true){\n    //\n    msg.payload = \"0\"\n}else{\n    msg.payload = \"2\"\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1870,
        "y": 260,
        "wires": [
            [
                "5c8481e1c8fbc1f2"
            ]
        ]
    },
    {
        "id": "55d3bc520aad4dce",
        "type": "bcrypt",
        "z": "f24308a3b5ba3065",
        "name": "",
        "action": "encrypt",
        "field": "payload",
        "hash": "payload",
        "target": "hashedPassword",
        "assignment": "assign",
        "match": "match",
        "outputs": 1,
        "rounds": 10,
        "x": 930,
        "y": 540,
        "wires": [
            [
                "72386f8c52890b0f"
            ]
        ]
    },
    {
        "id": "977ba86dfac2fcdb",
        "type": "change",
        "z": "f24308a3b5ba3065",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "hash",
                "pt": "flow",
                "to": "hashedPassword",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1410,
        "y": 540,
        "wires": [
            [
                "b99f05ccc1d87383"
            ]
        ]
    },
    {
        "id": "b99f05ccc1d87383",
        "type": "debug",
        "z": "f24308a3b5ba3065",
        "name": "debug 3400",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1600,
        "y": 540,
        "wires": []
    },
    {
        "id": "589f9a78e7339d88",
        "type": "bcrypt",
        "z": "f24308a3b5ba3065",
        "name": "",
        "action": "verify",
        "field": "payload",
        "hash": "hash",
        "target": "payload",
        "assignment": "replace",
        "match": "match",
        "outputs": 1,
        "rounds": 10,
        "x": 1680,
        "y": 260,
        "wires": [
            [
                "97cb53f549d8ebd0"
            ]
        ]
    },
    {
        "id": "5c8481e1c8fbc1f2",
        "type": "switch",
        "z": "f24308a3b5ba3065",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "2",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 2050,
        "y": 260,
        "wires": [
            [
                "36db41dafe050e0d"
            ],
            [
                "ac8b9b82257b3848"
            ]
        ]
    },
    {
        "id": "23139c6750c1e4b8",
        "type": "MySQLdatabase",
        "name": "",
        "host": "127.0.0.1",
        "port": "3306",
        "db": "project",
        "tz": "",
        "charset": "UTF8"
    },
    {
        "id": "c7079967a92c6224",
        "type": "ui_group",
        "name": "LogIn",
        "tab": "3ee156d8dba4fea3",
        "order": 1,
        "disp": false,
        "width": "8",
        "collapse": false,
        "className": "loginForm"
    },
    {
        "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
    }
]
  1. In Register user on MySQL why are you saving the hash in the database as 'password'?

  2. In addition in your function node ์ž…๋ ฅํ•œ value์— ๋Œ€ํ•ด set global what do you think will happen if the user ID or password is not filled in? How do you plan to handle that situation?

If you want help, please reply to all questions.