本文整理汇总了Python中database.DatabaseManager.check_password方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.check_password方法的具体用法?Python DatabaseManager.check_password怎么用?Python DatabaseManager.check_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.check_password方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_password
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def change_password():
db_manager = DatabaseManager()
username = request.json.get('username')
old_password = sha512_crypt.encrypt(request.json.get('old_password'), salt=app.config['SECURITY_PASSWORD_SALT'], rounds=5000)
new_password = sha512_crypt.encrypt(request.json.get('new_password'), salt=app.config['SECURITY_PASSWORD_SALT'], rounds=5000)
token = request.json.get('token')
# Not everything filled in
if username == None or old_password == None or new_password == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
return json.dumps({ 'username':'ERROR, No user' })
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
return json.dumps({ 'username':'ERROR, Wrong token'})
elif token_credentials[0] != username:
abort(401)
if db_manager.check_password(username, old_password):
db_manager.change_password(username, old_password, new_password)
return "Changed password"
else:
return "ERROR, Wrong password"
示例2: change_password
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def change_password():
db_manager = DatabaseManager()
username = request.json.get("username")
old_password = sha512_crypt.encrypt(
request.json.get("old_password"), salt=app.config["SECURITY_PASSWORD_SALT"], rounds=5000
)
new_password = sha512_crypt.encrypt(
request.json.get("new_password"), salt=app.config["SECURITY_PASSWORD_SALT"], rounds=5000
)
token = request.json.get("token")
# Not everything filled in
if username == None or old_password == None or new_password == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
if db_manager.check_password(username, old_password):
db_manager.change_password(username, old_password, new_password)
return response_cache_header("Changed password", cache_control="no-cache")
else:
return response_cache_header("ERROR, Wrong password", cache_control="no-cache")
示例3: authenticate
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def authenticate():
db_manager = DatabaseManager()
username = request.json.get("username")
password = sha512_crypt.encrypt(
request.json.get("password"), salt=app.config["SECURITY_PASSWORD_SALT"], rounds=5000
)
if username and password:
if db_manager.get_user(username):
if db_manager.get_user(username).get("email_verified"):
# Check password
if db_manager.check_password(username, password):
token = db_manager.generate_auth_token(username.lower(), password).decode("utf-8")
user_id = db_manager.get_user(username).get("id")
return response_cache_header(json.dumps({"token": token, "success": True}))
else:
return response_cache_header(
json.dumps({"error": "Incorrect password and/or username", "success": False}),
cache_control="no-cache",
)
else:
return response_cache_header(
json.dumps({"error": "Email not verified", "success": False}), cache_control="no-cache"
)
else:
return response_cache_header(
json.dumps({"error": "User does not exist", "success": False}), cache_control="no-cache"
)
else:
return Response("Login!", 401, {"WWW-Authenticate": 'Basic realm="Login!"'})
示例4: get_friends
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def get_friends():
db_manager = DatabaseManager()
username = request.json.get("username").lower()
token = request.json.get("token")
if username == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
friends = db_manager.get_friends_for_user(username)
# It is unsafe to send your friends password hash to the browser... email_verified and id aren't needed
for friend in friends:
if friend == None:
friends.remove(friend)
continue
del friend["password_hash"]
del friend["email_verified"]
del friend["id"]
return response_cache_header(json.dumps({"friends": friends}))
示例5: delete_list
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def delete_list():
db_manager = DatabaseManager()
username = request.json.get("username").lower()
listname = request.json.get("listname")
token = request.json.get("token")
if username == None or listname == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
if not db_manager.listname_exists_for_user(username, listname):
return response_cache_header("No list found", cache_control="no-cache")
if db_manager.listname_exists_for_user(username, listname):
db_manager.delete_list(username, listname)
return response_cache_header(json.dumps({"response": "Successfully deleted list"}), cache_control="no-cache")
return abort(401)
示例6: get
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def get(username):
db_manager = DatabaseManager()
token = request.json.get('token')
if token is None or token is "":
return abort(401)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
return abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
return abort(401)
if db_manager.username_exists(username):
# Return all lists
if token_credentials[0] == username:
user_info = db_manager.get_user(username)
list_lists = db_manager.get_lists_for_user(username)
for l in list_lists: del l['user_id']; del l['id']
return response_cache_header(json.dumps({
'username': user_info.get("username"),
'email' : user_info.get("email"),
'lists' : list_lists
}))
# Return friend lists if you are friends
elif db_manager.users_are_friends(username, token_credentials[0]):
user_info = db_manager.get_user(username)
list_lists = db_manager.get_lists_for_user(username)
for l in list_lists[:]: # Make a slice copy of the entire list
if l['shared_with'] == "0":
list_lists.remove(l)
del l['user_id']
del l['id']
return response_cache_header(json.dumps({
'username': user_info.get("username"),
'email' : user_info.get("email"),
'lists' : list_lists
}))
# Return everyone shared lists
else:
user_info = db_manager.get_user(username)
list_lists = db_manager.get_lists_for_user(username)
for l in list_lists[:]: # Make a slice copy of the entire list
if l['shared_with'] != "2":
list_lists.remove(l)
del l['user_id']
del l['id']
return response_cache_header(json.dumps({
'username': user_info.get("username"),
'email' : user_info.get("email"),
'lists' : list_lists
}))
else:
return response_cache_header(json.dumps({"error":"User not found"}), cache_control="no-cache")
示例7: delete_list
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def delete_list():
db_manager = DatabaseManager()
username = request.json.get('username')
listname = request.json.get('listname')
token = request.json.get('token')
if username == None or listname == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
return json.dumps({ 'username':'ERROR, No user' })
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
return json.dumps({ 'username':'ERROR, Wrong token'})
elif token_credentials[0] != username:
abort(401)
if not db_manager.listname_exists_for_user(username, listname):
return "No list found"
if db_manager.listname_exists_for_user(username, listname):
db_manager.delete_list(username, listname)
return "Successfully deleted list"
return abort(401)
示例8: show_user_list
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def show_user_list(username, listname):
db_manager = DatabaseManager()
token = request.json.get("token")
if token is None or token is "":
return json.dumps({ 'username':'ERROR, No token' })
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
return json.dumps({ 'username':'ERROR, No user' })
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
return json.dumps({ 'username':'ERROR, Wrong token'})
if db_manager.username_exists(username):
if db_manager.listname_exists_for_user(username, listname):
list_data = db_manager.get_list(username, listname)
shared_with = list_data.get("shared_with")
translations = db_manager.get_translations_for_list(username, listname)
for translation in translations: del translation['id']; del translation['list_id']
# Check if is owner
if username == token_credentials[0]:
return json.dumps({
'listname' : listname,
'language_1_tag' : list_data.get("language_1_tag"),
'language_2_tag' : list_data.get("language_2_tag"),
'words' : translations,
'shared_with' : shared_with
})
# Check if is friend
elif shared_with == '1' and db_manager.users_are_friends(username, token_credentials[0]):
return json.dumps({
'listname' : listname,
'language_1_tag' : list_data.get("language_1_tag"),
'language_2_tag' : list_data.get("language_2_tag"),
'words' : translations,
'shared_with' : shared_with
})
elif shared_with == '2':
return json.dumps({
'listname' : listname,
'language_1_tag' : list_data.get("language_1_tag"),
'language_2_tag' : list_data.get("language_2_tag"),
'words' : translations,
'shared_with' : shared_with
})
else:
abort(401)
else:
return json.dumps({
'username': 'ERROR: This shouldn\'t happen'
})
else:
return json.dumps({
'username': 'ERROR: This shouldn\'t happen'
})
示例9: show_user_list
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def show_user_list(username, listname):
db_manager = DatabaseManager()
token = request.json.get("token")
if token is None or token is "":
return abort(401)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
return abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
return abort(401)
if db_manager.username_exists(username):
if db_manager.listname_exists_for_user(username, listname):
list_data = db_manager.get_list(username, listname)
shared_with = list_data.get("shared_with")
translations = db_manager.get_translations_for_list(username, listname)
for translation in translations: del translation['id']; del translation['list_id']
# Check if is owner
if username == token_credentials[0]:
return response_cache_header(json.dumps({
'listname' : listname,
'language_1_tag' : list_data.get("language_1_tag"),
'language_2_tag' : list_data.get("language_2_tag"),
'words' : translations,
'shared_with' : shared_with
}))
# Check if is friend
elif shared_with == '1' and db_manager.users_are_friends(username, token_credentials[0]):
return response_cache_header(json.dumps({
'listname' : listname,
'language_1_tag' : list_data.get("language_1_tag"),
'language_2_tag' : list_data.get("language_2_tag"),
'words' : translations,
'shared_with' : shared_with
}))
elif shared_with == '2':
return response_cache_header(json.dumps({
'listname' : listname,
'language_1_tag' : list_data.get("language_1_tag"),
'language_2_tag' : list_data.get("language_2_tag"),
'words' : translations,
'shared_with' : shared_with
}))
else:
abort(401)
else:
return response_cache_header(json.dumps({"error":"List not found"}), cache_control="no-cache")
else:
return response_cache_header(json.dumps({"error":"User not found"}), cache_control="no-cache")
示例10: authenticate
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def authenticate():
db_manager = DatabaseManager()
username = request.json.get('username')
password = sha512_crypt.encrypt(request.json.get('password'), salt=app.config['SECURITY_PASSWORD_SALT'], rounds=5000)
if username and password:
if db_manager.get_user(username):
if db_manager.get_user(username).get('email_verified'):
# Check password
if db_manager.check_password(username, password):
return response_cache_header(json.dumps({
"token": db_manager.generate_auth_token(username, password).decode("utf-8")
}))
else:
return response_cache_header(json.dumps({"error":"Email not verified"}), cache_control="no-cache")
else:
return response_cache_header(json.dumps({"error":"User not found"}), cache_control="no-cache")
else:
return Response('Login!', 401, {'WWW-Authenticate': 'Basic realm="Login!"'})
示例11: save_list
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def save_list():
db_manager = DatabaseManager()
username = request.json.get('username')
list_data = request.json.get('list_data')
token = request.json.get('token')
if username == None or list_data == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
if list_data.get('listname') is None or list_data.get('language_1_tag') is None or list_data.get('language_2_tag') is None or list_data.get('shared_with') is None:
abort(400)
if list_data.get('listname') is "" or list_data.get('language_1_tag') is "" or list_data.get('language_2_tag') is "" or list_data.get('shared_with') is "":
abort(400)
if db_manager.listname_exists_for_user(username, list_data.get('listname')):
db_manager.delete_list(username, list_data.get('listname'))
db_manager.create_list(username, list_data.get('listname'), list_data.get('language_1_tag'), list_data.get('language_2_tag'), list_data.get('shared_with'))
words = list_data.get('words')
for i in range(len(words)):
word = words[i]
if word.get('language_1_text') is u'' or word.get('language_2_text') is u'':
continue
db_manager.create_translation(username, list_data.get('listname'), word.get('language_1_text'), word.get('language_2_text'))
return response_cache_header("Saved list", cache_control="no-cache")
示例12: get_friends
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def get_friends():
db_manager = DatabaseManager()
username = request.json.get('username')
token = request.json.get('token')
if username == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
friends = db_manager.get_friends_for_user(username)
# It is unsafe to send your friends password hash to the browser... email_verified and id aren't needed
for friend in friends: del friend['password_hash']; del friend['email_verified']; del friend['id']
return response_cache_header(json.dumps({"friends":friends}))
示例13: save_list
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def save_list():
db_manager = DatabaseManager()
username = request.json.get("username").lower()
list_data = request.json.get("list_data")
token = request.json.get("token")
if username == None or list_data == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
if len(list_data.get("listname")) > 20:
print(list_data["listname"][:20])
list_data["listname"] = list_data["listname"][:20]
if (
list_data.get("listname") is None
or list_data.get("language_1_tag") is None
or list_data.get("language_2_tag") is None
or list_data.get("shared_with") is None
):
abort(400)
if (
list_data.get("listname") is ""
or list_data.get("language_1_tag") is ""
or list_data.get("language_2_tag") is ""
or list_data.get("shared_with") is ""
):
abort(400)
if db_manager.listname_exists_for_user(username, list_data.get("listname")):
old_list = db_manager.get_list(username, list_data["listname"])
old_words = db_manager.get_translations_for_list(username, list_data["listname"])
db_manager.delete_list(username, list_data.get("listname"))
db_manager.create_list(
username,
list_data.get("listname"),
list_data.get("language_1_tag"),
list_data.get("language_2_tag"),
list_data.get("shared_with"),
)
words = list_data.get("words")
for i in range(len(words)):
word = words[i]
if word.get("language_1_text") is u"" or word.get("language_2_text") is u"":
continue
db_manager.create_translation(
username, list_data.get("listname"), word.get("language_1_text"), word.get("language_2_text")
)
return response_cache_header(
json.dumps({"response": "List exists", "old_list": old_list, "old_words": old_words}),
cache_control="no-cache",
)
db_manager.create_list(
username,
list_data.get("listname"),
list_data.get("language_1_tag"),
list_data.get("language_2_tag"),
list_data.get("shared_with"),
)
words = list_data.get("words")
for i in range(len(words)):
word = words[i]
if word.get("language_1_text") is u"" or word.get("language_2_text") is u"":
continue
db_manager.create_translation(
username, list_data.get("listname"), word.get("language_1_text"), word.get("language_2_text")
)
return response_cache_header(
json.dumps({"response": "Saved list!", "listname": list_data.get("listname")}), cache_control="no-cache"
)
示例14: get
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_password [as 别名]
def get(username):
db_manager = DatabaseManager()
token = request.json.get('token')
if token is None or token is "":
return json.dumps({ 'username':'ERROR, No token' })
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
return json.dumps({ 'username':'ERROR, No user' })
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
return json.dumps({ 'username':'ERROR, Wrong token'})
if db_manager.username_exists(username):
# Return all lists
if token_credentials[0] == username:
user_info = db_manager.get_user(username)
list_lists = db_manager.get_lists_for_user(username)
for l in list_lists: del l['user_id']; del l['id']
return json.dumps({
'username': user_info.get("username"),
'email' : user_info.get("email"),
'lists' : list_lists
})
# Return friend lists if you are friends
elif db_manager.users_are_friends(username, token_credentials[0]):
user_info = db_manager.get_user(username)
list_lists = db_manager.get_lists_for_user(username)
for l in list_lists:
if l['shared_with'] == "0":
list_lists.remove(l)
del l['user_id']
del l['id']
return json.dumps({
'username': user_info.get("username"),
'email' : user_info.get("email"),
'lists' : list_lists
})
# Return everyone shared lists
else:
user_info = db_manager.get_user(username)
list_lists = db_manager.get_lists_for_user(username)
for l in list_lists:
if l['shared_with'] != "2":
list_lists.remove(l)
del l['user_id']
del l['id']
return json.dumps({
'username': user_info.get("username"),
'email' : user_info.get("email"),
'lists' : list_lists
})
else:
return json.dumps({
'username': 'ERROR: This shouldn\'t happen'
})