I started with Node-red a short time ago and also felt the need for a credential system for my dashboard a lot. As there is nothing native, I created a simple system, a "sticker".
Many beginners, even those who know very little about programming, from time to time have the same need.
That's why I decided to share this simple flow for locking and unlocking menus with password and user.
Just implement the code, insert the user and password you want in the function node responsible for the comparison and insert the other menus that will be hidden or shown as exemplified in the flow.
An interesting point is that the flow redirects the user to login, if he tries to access the tabs through the link with permission denied, for example.
I emphasize that it is a simple system, to be implemented in local applications, without exposure to the internet. In these cases there is no security.
the idea is just to have a kind of privacy at a local level, not leaving the guides so exposed.
I hope it will be useful for some beginner as well as me.
[{"id":"64c3a11c.be78a","type":"ui_form","z":"626d4279.e54a0c","name":"Form for entering data","label":"","group":"4e15518d.02b1a","order":1,"width":6,"height":3,"options":[{"label":"User","value":"User","type":"text","required":true,"rows":null},{"label":"Password","value":"Password","type":"password","required":true,"rows":null}],"formValue":{"User":"","Password":""},"payload":"","submit":"OK","cancel":"Cancel","topic":"mi","x":440,"y":360,"wires":[["4481aeff.d1662","3cca91f3.b0ed6e"]]},{"id":"5702ed7b.667e54","type":"ui_ui_control","z":"626d4279.e54a0c","name":"","events":"change","x":1340,"y":360,"wires":[["6ff5ae08.7992b"]]},{"id":"138bb241.8243ee","type":"ui_ui_control","z":"626d4279.e54a0c","name":"","events":"all","x":1320,"y":840,"wires":[[]]},{"id":"2880f2d8.ea9e4e","type":"join","z":"626d4279.e54a0c","name":"returns the current authorization if the system is \"moved\"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":950,"y":460,"wires":[["aa498102.d0df3","ea0e0132.070e6","2a42864d.3190da"]]},{"id":"4481aeff.d1662","type":"function","z":"626d4279.e54a0c","name":"Verify password/user","func":"if ((msg.payload.User == \"admin\")&& (msg.payload.Password == \"123\"))\n{msg.payload = \"granted\"\nmsg.topic = \"authorization\"\n return msg;\n \n}\nelse \n{\n msg.payload = \"denied\"\n msg.topic = \"authorization\"\nreturn msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":300,"wires":[["2880f2d8.ea9e4e","606b8d73.f27144"]]},{"id":"6ff5ae08.7992b","type":"function","z":"626d4279.e54a0c","name":"redirects to login if authorization = denied ","func":"\nmsg.topic = \"tab\"\nmsg.payload = msg.tab;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1440,"y":420,"wires":[["2880f2d8.ea9e4e"]]},{"id":"aa498102.d0df3","type":"function","z":"626d4279.e54a0c","name":"Flashing LEDs","func":"if (msg.payload.authorization == \"denied\")\n{\nmsg.payload = {\"tabs\": {\"hide\": \"Flashing LEDs\", \"disable\": [\"secret_tab\", \"unused_stuff\"]}}\nreturn msg;\n}\nif (msg.payload.authorization == \"granted\")\n{\nmsg.payload = {\"tabs\": {\"show\": \"Flashing LEDs\", \"enabled\": [\"secret_tab\", \"unused_stuff\"]}}\nreturn msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":920,"y":660,"wires":[["138bb241.8243ee"]]},{"id":"3cca91f3.b0ed6e","type":"function","z":"626d4279.e54a0c","name":"Verify failure notification","func":"if ((msg.payload.User == \"admin\")&& (msg.payload.Password == \"123\"))\n{\n msg.payload = \" \"\n return msg;\n \n}\nelse \n{\n msg.payload = \"Incorrect username or password.\"\n msg.topic = \"authorization\"\nreturn msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":340,"wires":[["bbc9ae5a.da221"]]},{"id":"bbc9ae5a.da221","type":"ui_text","z":"626d4279.e54a0c","group":"4e15518d.02b1a","order":2,"width":6,"height":1,"name":"Notification","label":"","format":"<font color = red >{{msg.payload}}</font>","layout":"col-center","x":710,"y":380,"wires":[]},{"id":"741ca1e6.cb9f2","type":"ui_button","z":"626d4279.e54a0c","name":"exit button","group":"f590a74e.55cc88","order":1,"width":6,"height":1,"passthru":false,"label":" Go out","tooltip":"","color":"","bgcolor":"","icon":"","payload":"denied","payloadType":"str","topic":"authorization","x":1110,"y":300,"wires":[["2880f2d8.ea9e4e","555593ed.25976c"]]},{"id":"95da46b4.8883a8","type":"ui_ui_control","z":"626d4279.e54a0c","name":"","events":"all","x":1320,"y":900,"wires":[[]]},{"id":"4c18c95c.70a4c8","type":"function","z":"626d4279.e54a0c","name":"redirects to start tab if authorization = granted","func":"if (msg.payload == \"granted\")\n{\n msg.payload = {\"tab\":\"start\"}\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":880,"wires":[["95da46b4.8883a8","84cb9151.ecbb2","27a32586.def47a"]]},{"id":"606b8d73.f27144","type":"delay","z":"626d4279.e54a0c","name":"","pauseType":"delay","timeout":"0.5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":650,"y":680,"wires":[["4c18c95c.70a4c8"]]},{"id":"84cb9151.ecbb2","type":"function","z":"626d4279.e54a0c","name":"clear user ","func":"\nmsg.payload.User = ''\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":840,"wires":[["64c3a11c.be78a"]]},{"id":"27a32586.def47a","type":"function","z":"626d4279.e54a0c","name":"clear password","func":"msg.payload.Password = ''\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":920,"wires":[["64c3a11c.be78a"]]},{"id":"555593ed.25976c","type":"function","z":"626d4279.e54a0c","name":"show the login tab","func":"msg.payload = {\"tabs\": {\"show\": \"Login\", \"enabled\": [\"secret_tab\", \"unused_stuff\"]}} \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1350,"y":300,"wires":[["5702ed7b.667e54"]]},{"id":"ea0e0132.070e6","type":"function","z":"626d4279.e54a0c","name":"hide login if authorization is = granted","func":"if (msg.payload.authorization == \"denied\")\n{\n msg.payload = {\"tab\":\"Login\"}\n return msg;\n}\nif (msg.payload.authorization == \"granted\")\n{\nmsg.payload = {\"tabs\": {\"hide\": \"Login\", \"disable\": [\"secret_tab\", \"unused_stuff\"]}} \nreturn msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1430,"y":500,"wires":[["138bb241.8243ee"]]},{"id":"d6d2765.6067288","type":"inject","z":"626d4279.e54a0c","name":"Initial injection. Locks on startup.","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":440,"y":300,"wires":[["4481aeff.d1662"]]},{"id":"82b32ccc.1e3f2","type":"comment","z":"626d4279.e54a0c","name":"these function nodes are where the other tabs are inserted. If permission is denied they are inaccessible and vice versa.","info":"\nthese function nodes are where the other tabs are inserted. If permission is denied they are inaccessible and vice versa.","x":940,"y":560,"wires":[]},{"id":"2a42864d.3190da","type":"function","z":"626d4279.e54a0c","name":"start tab","func":"if (msg.payload.authorization == \"denied\")\n{\nmsg.payload = {\"tabs\": {\"hide\": \"start\", \"disable\": [\"secret_tab\", \"unused_stuff\"]}}\nreturn msg;\n}\nif (msg.payload.authorization == \"granted\")\n{\nmsg.payload = {\"tabs\": {\"show\": \"start\", \"enabled\": [\"secret_tab\", \"unused_stuff\"]}}\nreturn msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":900,"y":600,"wires":[["138bb241.8243ee"]]},{"id":"4e15518d.02b1a","type":"ui_group","name":"indicate your credentials","tab":"d9365e0f.e1bf6","order":1,"disp":true,"width":"6","collapse":false},{"id":"f590a74e.55cc88","type":"ui_group","name":"Default","tab":"5677487e.117ef8","order":1,"disp":true,"width":"6","collapse":false},{"id":"d9365e0f.e1bf6","type":"ui_tab","name":"Login","icon":"lock","order":18,"disabled":false,"hidden":false},{"id":"5677487e.117ef8","type":"ui_tab","name":"start","icon":"dashboard","disabled":false,"hidden":false}]