Advertisement
AntonioVillanueva

Flask pyhton basic auth

Jan 10th, 2023
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. """
  2. Flask basic auth
  3. Erreur no login no password
  4. curl -i http://localhost:5000
  5. OK
  6. curl -i http://localhost:5000 -u "axiome:concept"
  7. """
  8. from flask import Flask
  9. from flask import jsonify
  10. from flask_httpauth import HTTPBasicAuth
  11. from werkzeug.security import generate_password_hash, check_password_hash
  12.  
  13. app = Flask(__name__)
  14. auth = HTTPBasicAuth()
  15.  
  16. users = {
  17.     "axiome": generate_password_hash("concept"),
  18.     "tony": generate_password_hash("icaro")
  19. }
  20.  
  21. @auth.verify_password
  22. def verify_password(username, password):
  23.     if username in users and \
  24.             check_password_hash(users.get(username), password):
  25.         return username
  26.  
  27.  
  28. @app.route("/")
  29. @auth.login_required
  30. def default():
  31.     """page Web par défaut """
  32.     return jsonify({'Base Web address':"axiome"})    
  33.  
  34. if __name__ == '__main__':
  35.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement