本文整理汇总了Python中cryptacular.bcrypt.BCRYPTPasswordManager.encode方法的典型用法代码示例。如果您正苦于以下问题:Python BCRYPTPasswordManager.encode方法的具体用法?Python BCRYPTPasswordManager.encode怎么用?Python BCRYPTPasswordManager.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptacular.bcrypt.BCRYPTPasswordManager
的用法示例。
在下文中一共展示了BCRYPTPasswordManager.encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def main():
"""Create a configured wsgi app"""
settings = {}
debug = os.environ.get('DEBUG', True)
settings['reload_all'] = debug
settings['debug_all'] = debug
settings['auth.username'] = os.environ.get('AUTH_USERNAME', 'admin')
manager = BCRYPTPasswordManager()
settings['auth.password'] = os.environ.get(
'AUTH_PASSWORD', manager.encode('secret'))
if not os.environ.get('TESTING', False):
# only bind the session if we are not testing
engine = sa.create_engine(DATABASE_URL)
DBSession.configure(bind=engine)
# add a secret value for auth tkt signing
auth_secret = os.environ.get('JOURNAL_AUTH_SECRET', 'itsaseekrit')
# configuration setup
config = Configurator(
settings=settings,
authentication_policy=AuthTktAuthenticationPolicy(
secret=auth_secret,
hashalg='sha512'
),
authorization_policy=ACLAuthorizationPolicy(),
)
config.include('pyramid_tm')
config.include('pyramid_jinja2')
config.add_route('home', '/')
config.add_route('add', '/add')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_static_view('static', os.path.join(HERE, 'static'))
config.scan()
app = config.make_wsgi_app()
return app
示例2: main
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def main(argv=None):
if len(argv) != 3:
print "Usage: create_user.py <username> <password>"
sys.exit(1)
session = dbsession()
username = argv[1]
password = argv[2]
manager = BCRYPTPasswordManager()
hashed_password = manager.encode(password)
user = User()
user.username = username
user.password = hashed_password
user.active_ind = True
try:
session.add(user)
session.commit()
print "User {0} created.".format(username)
except:
print "Error adding user."
session.rollback()
session.close()
sys.exit(1)
session.close()
sys.exit(0)
示例3: test_shorthash
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def test_shorthash(self):
manager = BCRYPTPasswordManager()
def match(hash):
return True
manager.match = match
short_hash = manager.encode(self.snowpass)[:28]
assert_true(manager.match(short_hash))
manager.check(short_hash, self.snowpass)
示例4: main
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
@forbidden_view_config(renderer='templates/forbidden.jinja2')
def forbidden(request):
return {}
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
auth_secret = os.environ.get('TASTEBUDDIES_AUTH_SECRET', 'tastynoms')
authn_policy = AuthTktAuthenticationPolicy(
secret=auth_secret,
hashalg='sha512',
callback=groupfinder,
)
authz_policy = ACLAuthorizationPolicy()
settings['auth.username'] = os.environ.get('AUTH_USERNAME', 'admin')
manager = BCRYPTPasswordManager()
settings['auth.password'] = os.environ.get(
'AUTH_PASSWORD', manager.encode('secret')
)
config = Configurator(
settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
)
config.include('pyramid_jinja2')
config.include('pyramid_tm')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('user_create', '/create_user')
config.add_route('user_login', '/login')
config.add_route('verify', '/verify', factory=Root)
config.add_route('send_email', '/send_email', factory=Root)
config.add_route('logout', '/logout', factory=Root)
config.add_route('profile_edit', '/profile/edit/{username}',
factory=Root)
config.add_route('group_create', '/group/create_group',
factory=Root)
config.add_route('group_edit', '/group/edit/{group_name}',
factory=Root)
config.add_route('profile_detail', '/profile/{username}',
factory=UserFactory, traverse='/{username}')
config.add_route('group_detail', '/group/{group_name}',
factory=Root)
config.scan()
return config.make_wsgi_app()
示例5: _set_password
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def _set_password(self, raw_password):
""" Encrypt the password.
Encrypt `raw_password` with bcrypt and set it as the account
password.
:param raw_password: the unencrypted user password
:type username: unicode
:return: the bcrypt encrypted password
:rtype: unicode
"""
bcrypt = BCRYPTPasswordManager()
self._password = unicode(bcrypt.encode(raw_password, rounds=12))
示例6: _initTestingDB
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def _initTestingDB(makeuser=False):
engine = create_engine('sqlite://')
Base.metadata.create_all(engine)
DBSession.configure(bind=engine)
if makeuser:
m = BPM()
hashed = m.encode(u'1234567')
with transaction.manager:
user = User(email=u'[email protected]',
password=hashed,
)
DBSession.add(user)
return DBSession
示例7: auth_req
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def auth_req(request):
manager = BCRYPTPasswordManager()
settings = {
'auth.username': 'admin',
'auth.password': manager.encode('secret'),
}
testing.setUp(settings=settings)
req = testing.DummyRequest()
def cleanup():
testing.tearDown()
request.addfinalizer(cleanup)
return req
示例8: new
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def new(cls, username=None, password=None, session=DBSession):
"""Stores password in database already hashed"""
manager = BCRYPTPasswordManager()
if not (username and password):
raise ValueError("Username and password needed")
hashed = unicode(manager.encode(password))
try:
instance = cls(username=username, password=hashed)
session.add(instance)
session.flush()
except IntegrityError:
raise ValueError("Username already in use")
return instance
示例9: create_user
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def create_user(cls, username, password, first="", last="",
dflt_medium=1, timezone='America/Los_Angeles',
session=None):
"""Instantiates a new user, and writes it to the database.
User must supply a username and password.
"""
if session is None:
session = DBSession
manager = BCRYPTPasswordManager()
hashed = manager.encode(password)
instance = cls(first=first, last=last, username=username,
password=hashed, dflt_medium=dflt_medium,
timezone=timezone)
session.add(instance)
session.flush()
return instance
示例10: main
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
manager = BCRYPTPasswordManager()
pw = getpass.getpass('Admin password: ')
hashed = manager.encode(pw)
with transaction.manager:
admin = User(username=u'admin', email='[email protected]', password=hashed)
DBSession.add(admin)
示例11: main
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
if 'DATABASE_URL' in os.environ:
settings['sqlalchemy.url'] = os.environ['DATABASE_URL']
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
manager = Manager()
password = manager.encode(u'admin')
admin = User(username=u'admin', hashed_password=password)
DBSession.add(admin)
示例12: main
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
manager = Manager()
password = manager.encode('admin')
DBSession.add(Entry(title=u'title', body=u'body'))
DBSession.add(User(username=u'admin', password=password))
示例13: main
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def main():
# Create a configured wsgi app
settings = {}
debug = os.environ.get('DEBUG', True)
settings['reload_all'] = debug
settings['debug_all'] = debug
settings['auth.username'] = os.environ.get('AUTH_USERNAME', 'admin')
manager = BCRYPTPasswordManager()
settings['auth.password'] = os.environ.get(
'AUTH_PASSWORD', manager.encode('secret')
)
if not os.environ.get("TESTING", False):
# only bind the session if it isn't already bound, while testing
engine = sa.create_engine(DATABASE_URL)
DBSession.configure(bind=engine)
# add a secret value for auth tkt signing
auth_secret = os.environ.get('JOURNAL_AUTH_SECRET', 'itsaseekrit')
# and add a new value to the constructor for our Configurator:
config = Configurator(
settings=settings,
authentication_policy=AuthTktAuthenticationPolicy(
secret=auth_secret,
hashalg='sha512',
),
authorization_policy=ACLAuthorizationPolicy(),
)
# we want to use the transaction management provided by pyramid-tm
config.include("pyramid_tm")
config.include("pyramid_jinja2")
config.add_static_view('static', os.path.join(HERE, 'static'))
config.add_route('home', '/')
config.add_route('detail', '/detail/{id}')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('edit', '/edit/{entry_id}')
config.add_route('create', '/create')
config.scan()
app = config.make_wsgi_app()
return app
示例14: edit_user
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def edit_user(request):
user = request.context
if request.method == 'POST':
user.username = request.authenticated_userid
password = request.params.get('password')
manager = BCRYPTPasswordManager()
hashed = manager.encode(password)
user.password = hashed
user.first_name = request.params.get('first_name')
user.last_name = request.params.get('last_name')
default_medium = request.params.get('default_medium').lower()
if default_medium == 'email':
user.dflt_medium = 1
if default_medium == 'text':
user.dflt_medium = 2
else:
raise ValueError()
user.timezone = request.params.get('timezone')
return HTTPFound(request.route_url('list'))
else:
return {'user': user}
示例15: main
# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import encode [as 别名]
def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
m = BPM()
a_email = raw_input('Enter email for admin account: ')
a_pw = getpass('Enter password for admin account: ')
a_hashed = m.encode(a_pw)
with transaction.manager:
admin = User(
email=a_email,
password=a_hashed,
)
DBSession.add(admin)