本文整理汇总了Python中sql_manager.login函数的典型用法代码示例。如果您正苦于以下问题:Python login函数的具体用法?Python login怎么用?Python login使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了login函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_change_password
def test_change_password(self):
logged_user = sql_manager.login('Tester', 'asdaFGG45g*&')
new_password = "mvxza23g5g!~"
sql_manager.change_pass(new_password, logged_user)
logged_user_new_password = sql_manager.login('Tester', new_password)
self.assertEqual(logged_user_new_password.get_username(), 'Tester')
示例2: test_login_wrong_password_5_in_row
def test_login_wrong_password_5_in_row(self):
logged_user = sql_manager.login('Tester', '123567')
logged_user = sql_manager.login('Tester', '123567')
logged_user = sql_manager.login('Tester', '123567')
logged_user = sql_manager.login('Tester', '123567')
logged_user = sql_manager.login('Tester', '123567')
self.assertFalse(logged_user)
示例3: test_change_password
def test_change_password(self):
logged_user = sql_manager.login("Tester", STRONG_PASSWORD1)
new_password = "12345"
sql_manager.change_pass(new_password, logged_user)
logged_user_new_password = sql_manager.login("Tester", new_password)
self.assertEqual(logged_user_new_password.get_username(), "Tester")
示例4: main_menu
def main_menu():
print("Welcome to our bank service. You are not logged in. \nPlease register or login")
while True:
command = input("$$$>").split(" ")
if command[0] == "register":
username = input("Enter your username: ")
os.system("stty -echo")
password = input("Enter your password: ")
os.system("stty echo")
email = input("Enter your email address: ")
print(sql_manager.register(username, password, email))
elif command[0] == "login":
username = input("Enter your username: ")
os.system("stty -echo")
password = input("Enter your password: ")
os.system("stty echo")
logged_user = sql_manager.login(username, password)
if logged_user:
logged_menu(logged_user)
else:
print("Login failed")
elif command[0] == "reset-password":
if not sql_manager.check_if_username_exists(command[1]):
print("Invalid username/password.")
else:
sql_manager.clear_login_attempts(command[1])
sql_manager.send_reset_password(command[1])
correct = False
while correct is False:
probable_hash = input("Please enter the code you have received in the email: ")
if sql_manager.check_if_hashes_match(command[1], probable_hash):
correct = True
sql_manager.login(command[1], probable_hash)
os.system("stty -echo")
new_password = input("Please enter your new password: ")
os.system("stty echo")
while sql_manager.check_password_strength(command[1], new_password) is False:
os.system("stty -echo")
new_password = input("Please enter a valid password: ")
os.system("stty echo")
sql_manager.change_pass(new_password, command[1])
elif command[0] == "help":
print("help - for displaying this message!")
print("login - for logging in!")
print("register - for creating new account!")
print("reset-password <username> - for resetting forgotten password!")
print("exit - for closing program!")
elif command == "exit":
break
else:
print("Not a valid command")
示例5: test_change_password_with_sql_injection
def test_change_password_with_sql_injection(self):
sql_manager.register('Dinko', STRONG_PASSWORD1)
sql_manager.register('Vladko', STRONG_PASSWORD2)
logged_user = sql_manager.login('Dinko', STRONG_PASSWORD1)
new_password = "1234Asdf$$$Asdf' WHERE id = 3 --"
sql_manager.change_pass(new_password, logged_user)
self.assertFalse(sql_manager.login('Vladko', "1234Asdf$$$Asdf"))
示例6: login
def login():
username = input("Enter your username: ")
password = input("Enter your password: ")
try:
sql_manager.login(username, password)
logged_menu(username)
except UnsuccessfulLoginException as e:
print(e)
示例7: test_login
def test_login(self):
logged_user = sql_manager.login('Tester', '[email protected]')
self.assertEqual(logged_user.get_username(), 'Tester')
logged_user = sql_manager.login('\' OR 1==1--', '123')
self.assertFalse(logged_user)
logged_user = sql_manager.login('Blq', '\' OR 1==1--')
self.assertEqual(False,logged_user)
示例8: main_menu
def main_menu():
print("Welcome to our bank service. You are not logged in. \nPlease register or login")
while True:
command = input("$$$>")
if command == 'register':
result = print_username_password()
username = result['username']
password = result['password']
inp = sql_manager.register(username, password)
if inp == True:
print("Registration Successfull")
else:
print(inp['reason'])
elif command == 'login':
result = print_username_password()
username = result['username']
password = result['password']
logged_user = sql_manager.login(username, password)
if logged_user:
logged_menu(logged_user)
else:
print("Login failed")
elif command == 'help':
print_help()
elif command == 'exit':
break
else:
print("Not a valid command")
示例9: main_menu
def main_menu():
print("Welcome to our bank service. You are not logged in. \nPlease register or login")
while True:
command = input("$$$>")
if command == 'register':
username = input("Enter your username: ")
password = valid_password()
sql_manager.register(username, password)
print("Registration Successfull")
elif command == 'login':
username = input("Enter your username: ")
password = input("Enter your password: ")
logged_user = sql_manager.login(username, password)
if logged_user:
logged_menu(logged_user)
else:
print("Login failed")
elif command == 'help':
print("login - for logging in!")
print("register - for creating new account!")
print("exit - for closing program!")
elif command == 'exit':
break
else:
print("Not a valid command")
示例10: start
def start(self):
print(messages.WELCOME_MSG)
while True:
command = input("$$$>")
if command == 'register':
username = input("Enter your username: ")
password = input("Enter your password: ")
try:
sql_manager.register(username, password)
print(messages.SUCCESSFUL_REG_MSG)
except PasswordNotStrongError:
print(messages.STRONG_PASSWORD_ERROR_MSG)
elif command == 'login':
username = input("Enter your username: ")
password = getpass.getpass("Enter your password: ")
logged_user = sql_manager.login(username, password)
if logged_user:
self.logged_menu(logged_user)
else:
print(messages.LOGIN_FAIL_MSG)
elif command == 'help':
print("login - for logging in!")
print("register - for creating new account!")
print("exit - for closing program!")
elif command == 'exit':
break
else:
print("Not a valid command")
示例11: main_menu
def main_menu(conn, cursor):
print("Welcome to our bank service. You are not logged in. \nPlease register or login")
while True:
command = input("$$$>")
if command == 'register':
username = input("Enter a username: ")
password = getpass.getpass(prompt="Enter a password: ")
while not sql_manager.password_validation(username, password):
password = getpass.getpass(prompt="Enter a password again: ")
print("WEAK password")
sql_manager.register(conn, cursor, username, password)
print("Registration Successfull")
elif command == 'login':
count_wrong_input = 0
username = input("Enter your username: ")
password = ""
while not sql_manager.login(conn, cursor, username, password):
password = getpass.getpass(prompt="Enter your password: ")
count_wrong_input += 1
if count_wrong_input < 5:
continue
else:
print("You entered wrong password 5 times!")
boom = 30
while boom >= 0:
time.sleep(1)
print("You can enter you password again after:{}sec".format(boom), end='\r')
boom -= 1
count_wrong_input = 0
logged_user = sql_manager.login(conn, cursor, username, password)
if logged_user:
logged_menu(conn, cursor, logged_user)
else:
print("Login failed")
elif command == 'help':
print("login - for logging in!")
print("register - for creating new account!")
print("exit - for closing program!")
elif command == 'exit':
break
else:
print("Not a valid command")
示例12: main_menu
def main_menu():
failed_log_users = [1]
fail_log_counter = 0
wrong_pass_limit = 5
block_message = "you have 5 wrong password inputs\
\n and you`re blocked for 5 minutes"
print("Welcome to our bank service. You are not logged in.\
\nPlease register or login")
while True:
command = input("$$$>")
if command == 'register':
username = input("Enter your username: ")
password = pass_conditions(username)
hashed_pass = hash_password(password)
email = input("Enter your emal: ")
sql_manager.register(username, hashed_pass, email)
print("Registration Successfull")
elif command == 'login':
username = input("Enter your username: ")
password = getpass.getpass('Password:')
input_pass = hash_password(password)
logged_user = sql_manager.login(username)
existing_pass = sql_manager.get_user_pass(username)
is_pass_eq = sql_manager.check_password(input_pass, existing_pass) is True
if logged_user and is_pass_eq and can_login(username) is True:
fail_log_counter = 0
sql_manager.unbclock_user(username)
logged_menu(logged_user)
failed_log_users = [1]
else:
print("Login failed")
last_user = failed_log_users[len(failed_log_users) - 1]
if fail_log_counter >= wrong_pass_limit:
print(block_message)
if username == last_user:
fail_log_counter += 1
if fail_log_counter == wrong_pass_limit:
sql_manager.block_user(username)
fail_log_counter = 0
print(block_message)
else:
fail_log_counter = 1
failed_log_users.append(username)
elif command == 'help':
print("login - for logging in!")
print("register - for creating new account!")
print("exit - for closing program!")
elif command == 'exit':
break
else:
print("Not a valid command")
示例13: main_menu
def main_menu():
print("Welcome to our bank service. You are not logged in. \nPlease register or login")
while True:
command = input("$$$>").split(" ")
if command[0] == 'register':
username = input("Enter your username: ")
password = getpass.getpass("Enter your password: ")
while not sql_manager.is_strong(username, password):
print("Password is not strong enough!")
password = getpass.getpass("Enter your password: ")
email = input("Enter your email: ")
sql_manager.register(username, password, email)
print("Registration Successfull")
elif command[0] == 'login':
username = input("Enter your username: ")
password = getpass.getpass("Enter your password: ")
logged_user = sql_manager.login(username, password)
if logged_user:
logged_menu(logged_user)
else:
print("Login failed")
elif command[0] == "reset-password" and len(command) >1:
reset_hash = hashlib.sha1(str(random.random()).encode()).hexdigest()
sql_manager.update_reset_hash(command[1], reset_hash)
send_email.send_email(sql_manager.get_email(command[1]), reset_hash)
print(command[1])
elif command[0] == "send-reset-password" and len(command) > 1:
reset_hash = input("Enter reset hash: ")
if reset_hash == sql_manager.get_reset_hash(command[1]):
logged_user = sql_manager.login_with_hash(command[1], reset_hash)
if logged_user:
logged_menu(logged_user)
else:
print("Login failed")
elif command[0] == 'help':
print("login - for logging in!")
print("register - for creating new account!")
print("exit - for closing program!")
print("reset-password <name> - to reset password")
print("send-reset-password <name> - to enter reset password")
elif command[0] == 'exit':
break
else:
print("Not a valid command")
示例14: test_change_pass
def test_change_pass(self):
logged_user = sql_manager.login("user1", "Tu6^^^pass1")
sql_manager.change_pass("new_PASS123", logged_user)
conn = sqlite3.connect("bank.db")
cursor = conn.cursor()
select_query = "SELECT id, username, password FROM clients WHERE \
username = ? AND password = ? LIMIT 1"
cursor.execute(select_query, ("user1", sql_manager.hash_pass("new_PASS123")))
user = cursor.fetchone()
self.assertEqual("user1", user[1])
示例15: login
def login(cls):
username = input("Enter your username: ")
password = getpass.getpass(stream=None)
logged_user = sql_manager.login(username, password)
if logged_user:
cls.logged_menu(logged_user)
else:
print("Login failed")
return username