How to use bcrypt in Google App Engine (GAE)?

I found a bcrypt library for python that seems very easy to use:

After installing and testing the hello world example on my local machine, everything looks fine:

>>> import bcrypt
>>> password = b"super secret password"
>>> # Hash a password for the first time, with a certain number of rounds
>>> hashed = bcrypt.hashpw(password, bcrypt.gensalt(10))
>>> # Check that a unhashed password matches one that has previously been
>>> #   hashed
>>> if bcrypt.hashpw(password, hashed) == hashed:
...     print("It Matches!")
... else:
...     print("It Does not Match :(")

However, in my GAE application, when I use import bcrypt, I get an error message:

Traceback (most recent call last):
  File "/home/pedro/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/pedro/google_appengine/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/pedro/google_appengine/google/appengine/runtime/wsgi.py", line 84, in LoadObject
    obj = __import__(path[0])
  File "/home/pedro/google_appengine/hw4/blog.py", line 8, in <module>
    import bcrypt
ImportError: No module named bcrypt
INFO     2014-05-05 21:17:04,375 module.py:639] default: "GET /blog/signup HTTP/1.1" 500 -

This makes me think that I should modify the file app.yamlto include this library:

application: calm-grid-571
version: 1
runtime: python27
api_version: 1
threadsafe: False

handlers:
- url: /static
  static_dir: static

- url: /.*
  script: blog.app

libraries:
- name: jinja2
  version: latest

- name: PIL
  version: latest

However, when checking the official page of supported libraries, I can not find anything about bcrypt.

So how do I use the bcrypt library in GAE? Is it possible?

+4
source share
1

bcrypt ( ) . , libs ( , app.yaml), .

:/libs/bcrypt/

__init__.py , , . : from libs.bcrypt import bcrypt

EDIT: , python . py-bcrypt, , App Engine.

+5

Source: https://habr.com/ru/post/1539345/


All Articles