Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication Support #6

Closed
TheGuyDanish opened this issue Aug 17, 2024 · 1 comment
Closed

Authentication Support #6

TheGuyDanish opened this issue Aug 17, 2024 · 1 comment
Labels
enhancement New feature or request todo

Comments

@TheGuyDanish
Copy link
Contributor

Microdot supports using sessions to have some kind of identification. We could use this to provide authentication to reach the control panel, securing it from potential malicious actors.

The biggest challenge to this at the moment (as I see it) is storing the password. MicroPython provides a limited number of hashing functions and none of them are salted.

As such, the best-effort way to store a password would be something like:

import hashlib, binascii
# [...]
password = 'admin' # We'd grab this from an input, probably on the settings page.
hash = hashlib.sha256(password.encode())
hash_for_storage = binascii.hexlify(hash.digest())
CONFIG['users']['username'] = hash_for_storage

Then authentication could be handled as:

import hashlib, binascii
from microdot.session import Session, with_session
# [...]
username = 'admin' # This would be an input from a sign-in page. 
password = 'admin'  # Ditto
hash = hashlib.sha256(password.encode())
hash_for_comparison = binascii.hexlify(hash.digest())
if hash_for_comparison == CONFIG['users'][username]:
  session['username'] = username
  session.save()

For this to be relevant, #1 should be handled first.

Further reading/examples:
https://github.com/miguelgrinberg/microdot/blob/main/examples/sessions/login.py

@TheGuyDanish TheGuyDanish added enhancement New feature or request todo labels Aug 17, 2024
@TheGuyDanish
Copy link
Contributor Author

miguelgrinberg/microdot#217 seems to hold the easy answer to this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request todo
Projects
None yet
Development

No branches or pull requests

1 participant