# How to create a dictionary authenticator?

**URL:** https://discourse.jupyter.org/t/how-to-create-a-dictionary-authenticator/15503
**Category:** JupyterHub
**Tags:** jupyterhub, how-to, help-wanted
**Created:** [August 25, 2022, 8:22am UTC](https://discourse.jupyter.org/t/how-to-create-a-dictionary-authenticator/15503 "2022-08-25T08:22:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Dmfama20](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/dmfama20/32/7792_2.png) [@Dmfama20](https://discourse.jupyter.org/u/Dmfama20)
#### Post date: [August 25, 2022, 8:22am UTC](https://discourse.jupyter.org/t/how-to-create-a-dictionary-authenticator/15503/1 "2022-08-25T08:22:18Z")

</div>

Hi,  
I try to add a list of users and passwords to jupyterhub\_config.py. Based on the docs  
[https://jupyterhub.readthedocs.io/en/stable/reference/authenticators.html#how-the-base-authenticator-works](https://jupyterhub.readthedocs.io/en/stable/reference/authenticators.html#how-the-base-authenticator-works)  
I’ve tried the following

```auto
from jupyterhub.auth import Authenticator

class DictionaryAuthenticator(Authenticator):

    passwords = {'peter':'777'}
        
    async def authenticate(self, handler, data):
        if self.passwords.get(data['username']) == data['password']:
            return data['username']

c.JupyterHub.authenticator_class = 'DictionaryAuthenticator'

```

But when starting the container it throws the following error:

```auto
jupyterhub | File "/srv/jupyterhub/jupyterhub_config.py", line 55, in <module>
jupyterhub | from jupyterhub.auth import Authenticator
jupyterhub | ModuleNotFoundError: No module named 'jupyterhub'

```

What is the correct way to add this dictionary authenticator?  
TIA!  
Alex

---

<div class="post-metadata">

### Author: ![djangoliv](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/djangoliv/32/5329_2.png) [@djangoliv](https://discourse.jupyter.org/u/djangoliv)
#### Post date: [August 25, 2022, 9:57am UTC](https://discourse.jupyter.org/t/how-to-create-a-dictionary-authenticator/15503/2 "2022-08-25T09:57:03Z")

</div>

It looks like you don’t have jupyterhub installed.

Try:

> pip install jupyterhub

in your virtualenv.

---

<div class="post-metadata">

### Author: ![Dmfama20](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/dmfama20/32/7792_2.png) [@Dmfama20](https://discourse.jupyter.org/u/Dmfama20)
#### Post date: [August 25, 2022, 11:49am UTC](https://discourse.jupyter.org/t/how-to-create-a-dictionary-authenticator/15503/3 "2022-08-25T11:49:16Z")

</div>

Hey,

thank you! That’s it.  
But how should I refer to this new class:

```auto
c.JupyterHub.authenticator_class = 'Authenticator'

```

leads to the error

```auto
....instance must be a type, but 'Authenticator' could not be imported.....

```

Same error by using

```auto
c.JupyterHub.authenticator_class = 'DictionaryAuthenticator'

```

TIA!  
Alex

---

<div class="post-metadata">

### Author: ![djangoliv](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/djangoliv/32/5329_2.png) [@djangoliv](https://discourse.jupyter.org/u/djangoliv)
#### Post date: [August 26, 2022, 6:54am UTC](https://discourse.jupyter.org/t/how-to-create-a-dictionary-authenticator/15503/4 "2022-08-26T06:54:29Z")

</div>

Since your Class is defined directly in the jupyterhub\_config.py, you can try without quotes :

```auto
c.JupyterHub.authenticator_class = DictionaryAuthenticator

```

---

<div class="post-metadata">

### Author: ![Dmfama20](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/dmfama20/32/7792_2.png) [@Dmfama20](https://discourse.jupyter.org/u/Dmfama20)
#### Post date: [August 30, 2022, 7:52am UTC](https://discourse.jupyter.org/t/how-to-create-a-dictionary-authenticator/15503/5 "2022-08-30T07:52:09Z")

</div>

Perfect!  
It’s working 🙂
