# Node Red Authentication PW Hash issue

**URL:** https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472
**Category:** General
**Created:** [26 September 2018 19:27 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472 "2018-09-26T19:27:36Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![jfehl](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jfehl](https://discourse.nodered.org/u/jfehl)
#### Post date: [26 September 2018 19:27 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/1 "2018-09-26T19:27:36Z")

</div>

I am trying to apply authentication to my Node-Red. I am able to get the `setting.js` edited so that it requests Username and PW. I am able to insert a different username, however...using the node-red-admin Hash-pw, I am not able to get the password encryption to work properly. If I copy and paste the encryption from the `documentation` section of [Node-Red.org](http://Node-Red.org), it will accept "password", but if I copy and paste the generated hash for my chosen PW, it does not recognize it when I log in. I have tried multiple times and double checked my typing in the hash-pw. Thoughts?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [26 September 2018 22:34 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/2 "2018-09-26T22:34:11Z")

</div>

Please list

1. the actual commands you used
2. what platform is NR running on?
3. what OS and release?
4. what version of NR and node.js?

---

<div class="post-metadata">

### Author: ![jfehl](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jfehl](https://discourse.nodered.org/u/jfehl)
#### Post date: [27 September 2018 01:15 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/3 "2018-09-27T01:15:15Z")

</div>

1. At the command prompt I used: node-red-admin hash-pw
2. running on a windows pc
3. windows 7 professional (6.1.7601)
4. NR v0.18.7 .js v8.11.3

Thanks

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [27 September 2018 09:11 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/4 "2018-09-27T09:11:07Z")

</div>

You might want to try upgrading NR since the current version is v0.19.4

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [27 September 2018 09:14 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/5 "2018-09-27T09:14:56Z")

</div>

> [@zenofmud](#):
>
> You might want to try upgrading NR since the current version is v0.19.4

That is good advice, but entirely incidental to the question being asked.

@jfehl all I can say is double check you've copied the hash properly. There's not much else that can go wrong with this. You could also try the `node` command provided in the docs:

> Alternative, you can run the following command from within the Node-RED install directory:  
> `node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" your-password-here`

---

<div class="post-metadata">

### Author: ![jfehl](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jfehl](https://discourse.nodered.org/u/jfehl)
#### Post date: [27 September 2018 19:10 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/6 "2018-09-27T19:10:09Z")

</div>

So I determined what must have been happening. I have my instances of Node-Red starting on `System-Recovery` in Task Scheduler. Although I would do a `CNTR-C` and then `(y)` to stop the flows, it must have not been stopping Node-Red entirely. I went into Task Scheduler and Stopped Node-Red from there, I then performed all the steps required to generate and copy the hash-pw and everything works fine now. So the error must have been me not completely stopping Node-Red.

All works now as described in the `documentation`.

Thanks for the help.

---

<div class="post-metadata">

### Author: ![MarcoPiscopia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcopiscopia/32/6322_2.png) [@MarcoPiscopia](https://discourse.nodered.org/u/MarcoPiscopia)
#### Post date: [26 February 2019 06:18 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/7 "2019-02-26T06:18:39Z")

</div>

Dears I'm new in the forum and I came across this post. Actually what described has happened to me too. What I tryed more is to run more times for the same password: with my surprise, every time hash -pw generates a different hash. There's no way to change this even if node-red is stopped. ![Cattura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4b37e7077c0a696c735ad6c4927a2bbfd19e19c8.jpeg)  
Any suggestion?  
When I try node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" your-password-here I got this  
`module.js:549  
throw err;  
^

Error: Cannot find module 'bcryptjs'  
at Function.Module.\_resolveFilename (module.js:547:15)  
at Function.Module.\_load (module.js:474:25)  
at Module.require (module.js:596:17)  
at require (internal/module.js:11:18)  
at [eval]:1:13  
at ContextifyScript.Script.runInThisContext (vm.js:50:33)  
at Object.runInThisContext (vm.js:139:38)  
at Object. ([eval]-wrapper:6:22)  
at Module.\_compile (module.js:652:30)  
at evalScript (bootstrap\_node.js:463:27)  
`  
Thanks in advance

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [26 February 2019 08:17 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/8 "2019-02-26T08:17:44Z")

</div>

> [@MarcoPiscopia](#):
>
> What I tryed more is to run more times for the same password: with my surprise, every time hash -pw generates a different hash

That is expected behaviour - the hashing algorithm we use can generate different hashes for the same input. Is that the only issue you are reporting? Or did you have another problem?

As for the node command you ran - what directory were you in when you ran it? Were you in the node-red install directory as the documentation for the command says you need to be?

---

<div class="post-metadata">

### Author: ![MarcoPiscopia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcopiscopia/32/6322_2.png) [@MarcoPiscopia](https://discourse.nodered.org/u/MarcoPiscopia)
#### Post date: [26 February 2019 09:05 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/9 "2019-02-26T09:05:53Z")

</div>

few info: I'm running node-red on several raspbian releases. Behaviour is always the same.

"That is expected behavior - the hashing algorithm we use can generate different hashes for the same input. Is that the only issue you are reporting? Or did you have another problem?"  
would this mean "more possibilities" to discover my password"? ..as the hash let the system rebuild the password, if more hashes can be assigned to one password....  
Anyway, that could not be a concrete problem. The problem is that if I use any one of the generated hashes I can not have access to node red. It seems the only one is working is the hash of the exemple for "password".  
I ran the alternative command also in .node-red folder and also as root with same results

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [26 February 2019 23:27 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/10 "2019-02-26T23:27:10Z")

</div>

> [@MarcoPiscopia](#):
>
> I ran the alternative command also in .node-red folder and also as root with same results

> node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" your-password-here

You have to run the above command from the `node-red installation` directory. If you run from the home directory ` ~/.node-red` or from another directory it will not work.

See below how it works for me. Click in the image to zoom-in.

 ![a-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ec049ee1f99fcce8cd40d86e434577bc3252aa4c.png)

Also, be careful when selecting the `settings.js` you edit to include the password. It has to be the one existing in the user home directory ` ~/.node-red`

---

<div class="post-metadata">

### Author: ![MarcoPiscopia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcopiscopia/32/6322_2.png) [@MarcoPiscopia](https://discourse.nodered.org/u/MarcoPiscopia)
#### Post date: [17 March 2019 19:53 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/11 "2019-03-17T19:53:31Z")

</div>

Dear All thank you for your replies and I'm sorry for my absence (I was abroad for 2 weeks).  
Then, as soon as possible I will come through all the suggestions again to recheck the issue. For now,  
I can only show that even if I use the command in the right folder it doesn't work

 ![Cattura45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c9a47e022b82b530bda7a0ec834df0ba28f5588e.jpeg)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [17 March 2019 22:19 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/12 "2019-03-17T22:19:59Z")

</div>

To quote Andrei from the previous post...

> [@Andrei](#):
>
> You have to run the above command from the `node-red installation` directory. If you run from the home directory `~/.node-red` or from another directory it will not work.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [18 March 2019 09:10 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/13 "2019-03-18T09:10:14Z")

</div>

I think the docs could do with a bit of clarification on what is meant by the node-red install directory. For a standard installation on a pi or ubuntu I believe this is /usr/lib/node\_modules/node-red.

**[Edit]** corrected path above

---

<div class="post-metadata">

### Author: ![MarcoPiscopia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcopiscopia/32/6322_2.png) [@MarcoPiscopia](https://discourse.nodered.org/u/MarcoPiscopia)
#### Post date: [18 March 2019 11:00 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/14 "2019-03-18T11:00:28Z")

</div>

> [@Colin](#):
>
> /var/lib/node\_modules/node-red.

mmmh

 ![Cattura46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b92ffc251c80755bea4cac4fb081477d0e43f100.jpeg)

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 March 2019 11:12 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/15 "2019-03-18T11:12:09Z")

</div>

On the Pi, the module will be under `/usr/lib/node_modules`

---

<div class="post-metadata">

### Author: ![MarcoPiscopia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcopiscopia/32/6322_2.png) [@MarcoPiscopia](https://discourse.nodered.org/u/MarcoPiscopia)
#### Post date: [18 March 2019 11:39 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/16 "2019-03-18T11:39:00Z")

</div>

![Cattura48](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c2b14f7d2166879d1aefb739528730c21b904a14.jpeg)

same as root

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 March 2019 12:02 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/17 "2019-03-18T12:02:01Z")

</div>

Is there a `node-red` directory under `/usr/lib/node_modules` ? If so, _that_ is the directory you should be in

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [18 March 2019 12:11 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/18 "2019-03-18T12:11:11Z")

</div>

Yes, sorry, should be /usr/lib/node-modules/node-red as @knolleary says. Fingers not doing what they are told. I have corrected the previous post.

---

<div class="post-metadata">

### Author: ![MarcoPiscopia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcopiscopia/32/6322_2.png) [@MarcoPiscopia](https://discourse.nodered.org/u/MarcoPiscopia)
#### Post date: [18 March 2019 12:11 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/19 "2019-03-18T12:11:20Z")

</div>

thank you.  
Now it is able to generate hash under

pi@Raspberry:/usr/lib/node\_modules/node-red

directory. I'll check if the hash works and let everybody know.

---

<div class="post-metadata">

### Author: ![MarcoPiscopia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcopiscopia/32/6322_2.png) [@MarcoPiscopia](https://discourse.nodered.org/u/MarcoPiscopia)
#### Post date: [18 March 2019 16:10 UTC](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472/20 "2019-03-18T16:10:11Z")

</div>

Dears here I am with my results.  
Thanks again to knolleary I've done some checks.

With the command

node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" your-password-here

executed in the folder

pi@Raspberry:/usr/lib/node\_modules/node-red/

the generated hash works.

Anyway, I underline that the reference settings.js file I used is the one in

pi@Raspberry:/home/pi/.node-red/

folder. That in the previous folder seems not to have effect.

Even if some doubts are still in my mind (eg why the hash generated by "node-red-admin hash-pw" command doesn't work and why there are 2 settings.js), for now I have found a solution to make it work. Thanks in advance to those who will clarify the other doubts.

[Next page](https://discourse.nodered.org/t/node-red-authentication-pw-hash-issue/3472.md?page=2)
