本文整理汇总了Python中model.User.isPasswordValid方法的典型用法代码示例。如果您正苦于以下问题:Python User.isPasswordValid方法的具体用法?Python User.isPasswordValid怎么用?Python User.isPasswordValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.isPasswordValid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPassword
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import isPasswordValid [as 别名]
def testPassword(self):
# Valid passwords
password = '11111111'
self.assertTrue(User.isPasswordValid(password), 'Misqualified valid password: ' + password)
password = '111wr311111'
self.assertTrue(User.isPasswordValid(password), 'Misqualified valid password: ' + password)
password = 'asdasdawdas'
self.assertTrue(User.isPasswordValid(password), 'Misqualified valid password: ' + password)
# invalid passwords
password = '1234567'
self.assertFalse(User.isPasswordValid(password), 'Misqualified invalid password: ' + password)
password = ''
self.assertFalse(User.isPasswordValid(password), 'Misqualified invalid password: ' + password)
password = ' '
self.assertFalse(User.isPasswordValid(password), 'Misqualified invalid password: ' + password)
password = '12 3 4567'
self.assertFalse(User.isPasswordValid(password), 'Misqualified invalid password: ' + password)
password = 'asdasdasd;'
self.assertFalse(User.isPasswordValid(password), 'Misqualified invalid password: ' + password)
password = 'asdasdasd\''
self.assertFalse(User.isPasswordValid(password), 'Misqualified invalid password: ' + password)
password = 'asdasdasd"'
self.assertFalse(User.isPasswordValid(password), 'Misqualified invalid password: ' + password)
示例2: __register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import isPasswordValid [as 别名]
def __register(self, api):
""" Check incoming parameters and register user """
# Validate email
email = self.request.get(constants.VAR_NAME_EMAIL)
logging.info('User registering: ' + str(email))
if not User.isEmailValid(email) or User.isAlreadyRegistered(email):
logging.error('Email mismatched or already registered')
self.set_error(constants.STATUS_BAD_REQUEST,
self.gettext('REGISTER_ERROR'),
url=self.request.url)
return
# Validate password
password = self.request.get(constants.VAR_NAME_PASSWORD)
if not User.isPasswordValid(password):
logging.error('Invalid password')
self.set_error(constants.STATUS_BAD_REQUEST,
self.gettext('REGISTER_ERROR'),
url=self.request.url)
return
# Calculate password hash
salt_and_key = CryptoUtil.get_salt_and_key(password)
salt = salt_and_key[0]
key = salt_and_key[1]
# Create and store user object
user = User(key_name=email)
user.email = email.lower()
user.salt = salt
user.password = key
user.verified = False
user.put()
# Send email for verification
self.__send_verification(email)
if api == '':
# Display message
template_values = {
'message': self.gettext('PLEASE_CHECK_YOUR_EMAIL')
}
template = self.jinja2_env.get_template('staticmessage.html')
self.response.out.write(template.render(template_values))
self.ok()
示例3: __login
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import isPasswordValid [as 别名]
def __login(self):
""" Validate incoming parameters and log in user if all is ok """
# Validate email and get user from db
email = self.request.get(constants.VAR_NAME_EMAIL)
logging.info('User logging in: ' + str(email))
if not User.isEmailValid(email) or not User.isAlreadyRegistered(email):
logging.error('Email mismatched or not registered')
self.set_error(constants.STATUS_BAD_REQUEST,
self.gettext('LOGIN_ERROR'), url=self.request.url)
return
user = User.getUser(email.lower())
# Calculate password hash
password = self.request.get(constants.VAR_NAME_PASSWORD)
if not User.isPasswordValid(password):
logging.error('Invalid password')
self.set_error(constants.STATUS_BAD_REQUEST,
self.gettext('LOGIN_ERROR'), url=self.request.url)
return
key = CryptoUtil.getKey(password, user.salt)
# Validate password
if not user.password == key:
logging.error('Incorrect password for email')
self.set_error(constants.STATUS_BAD_REQUEST,
self.gettext('LOGIN_ERROR'), url=self.request.url)
return
# Check remember me
remember_string = self.request.get('remember').lower()
remember = remember_string != '' and remember_string != 'false'
if remember:
token_id = LoginToken.generate_id()
token = LoginToken()
token.tokenid = token_id
token.ip = self.request.remote_addr
token.user = email
token.put()
cookie_value = token.get_cookie_value()
delta = timedelta(days=constants.PERSISTENT_LOGIN_LIFETIME_DAYS)
self.response.set_cookie(constants.PERSISTENT_LOGIN_NAME,
cookie_value,
expires=datetime.utcnow() + delta,
path="/", httponly=True, secure=True)
# Log in user
if user.verified:
user.login(self.request.remote_addr)
session = get_current_session()
url = session.pop(constants.VAR_NAME_REDIRECT)
if url is None:
url = "/"
self.ok(url)
else:
logging.error('User unverified')
self.set_error(constants.STATUS_FORBIDDEN,
self.gettext('UNVERIFIED_PRE') +
' <a href=\"/User/Verify">' +
self.gettext('UNVERIFIED_HERE') +
'</a> ' +
self.gettext('UNVERIFIED_POST'),
url=self.request.url)
return