# Can one write a function for the \`users\` parameter in adminAuth section for the settings.js?

**URL:** <https://discourse.nodered.org/t/can-one-write-a-function-for-the-users-parameter-in-adminauth-section-for-the-settings-js/76392>\
**Category:** General\
**Created:** [10 March 2023 14:25 UTC](https://discourse.nodered.org/t/can-one-write-a-function-for-the-users-parameter-in-adminauth-section-for-the-settings-js/76392 "2023-03-10T14:25:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shan](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shan](https://discourse.nodered.org/u/Shan)\
**Post date:** [10 March 2023 14:25 UTC](https://discourse.nodered.org/t/can-one-write-a-function-for-the-users-parameter-in-adminauth-section-for-the-settings-js/76392/1 "2023-03-10T14:25:14Z")

</div>

Would a function actually work when trying to log into node-red admin ui:

```javascript
 adminAuth: {
           type: "credentials",
           users: function() {
             const creds = require("fs").readFileSync('/run/secrets/nodered-credentials', 'utf-8').split('\n')
             console.log(creds)
             let users = []
             creds.forEach(usercreds => {
               users.push(
                 {
                   username: usercreds.toString().slice(0, usercreds.indexOf(':')),
                   password: usercreds.toString().slice(usercreds.indexOf(':') + 1).replace("$2y","$2b"),
                   permissions: "*"
                 }
               )
             })
             return users
           }
        },

```

The value under `/run/secrets/nodered-credentials` is an `htpasswd` something that looks like:

```
admin:$2y$08$x9dYJIaLtdGXFydW2AL9s.YodrBDT3QxYHTcOliBuYSBPAUfHGpjO

```

At the moment in my `settings.js` file I can console log the values but I cannot log myself in

The console log for `users`

```auto
secure_nodered | [
secure_nodered | {
secure_nodered | username: 'admin',
secure_nodered | password: '$2b$08$x9dYJIaLtdGXFydW2AL9s.YodrBDT3QxYHTcOliBuYSBPAUfHGpjO',
secure_nodered | permissions: '*'
secure_nodered | }
secure_nodered | ]

```

---

<div class="post-metadata">

**Author:** ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)\
**Post date:** [10 March 2023 14:49 UTC](https://discourse.nodered.org/t/can-one-write-a-function-for-the-users-parameter-in-adminauth-section-for-the-settings-js/76392/2 "2023-03-10T14:49:49Z")

</div>

Hi!  
Are you aware of [this documentation](https://nodered.org/docs/user-guide/runtime/securing-node-red#user-permissions#custom-user-authentication)?

> [@Shan](#):
>
> Would a function actually work when trying to log into node-red admin ui:

Yes, it does - when setup accordingly.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [9 May 2023 14:50 UTC](https://discourse.nodered.org/t/can-one-write-a-function-for-the-users-parameter-in-adminauth-section-for-the-settings-js/76392/3 "2023-05-09T14:50:31Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
