Форум сайта python.su
Пр запуске такого скрипта:
#!/usr/bin/env python3.8 import getpass import pymysql import hashlib import uuid import re import time import pyinputplus as pyip import os from uuid import getnode as mac t = 4 print("-------------------------") print("<<<<<<<<<Welcome>>>>>>>>>") print("-------------------------") print("Please enter a username (after 3 unlucky attempts system will reboot)") while True: t -= 1 if t > 0: username = pyip.inputNum('Username (must be 12 numbers): ', min=111111111111, max=999999999999, limit=3) db = pymysql.connect("hostname","user","pass","db") # prepare a cursor object using cursor() method cursor = db.cursor() cursor.execute("SELECT userID, password from permissions") data = cursor.fetchone() dbuser, dbpass = data #dbuser, dbpass = str(data[0]), data[1] # disconnect from server db.close() if username == dbuser : while True: password = getpass.getpass(prompt="Enter secret password:") if (hashlib.sha1(password.encode()).hexdigest() == dbpass): print("Authentication success") break else: print("Bad password") t -= 1 if t > 0: print('Left attempts=>', t) else: print('System will reboot now...') time.sleep(3) # os.system("reboot") break else: print ("please try another username. This username is incorrect") continue break
# ./auth.py ------------------------- <<<<<<<<<Welcome>>>>>>>>> ------------------------- Please enter a username (after 3 unlucky attempts system will reboot) Username (must be 12 numbers): 659605758502 please try another username. This username is incorrect Username (must be 12 numbers): 659605758503 please try another username. This username is incorrect Username (must be 12 numbers): 659605758505 please try another username. This username is incorrect
Офлайн
while True: # 1 t -= 1 # 2 if t > 0: # 3 # bla-bla
Офлайн
наверное подвиснет)). Нужен в конце еще блок else: ? Так он вроде присутствует у меня…
Отредактировано ffrr (Окт. 29, 2020 10:47:11)
Офлайн
ffrrнеа
Так он вроде присутствует у меня…
Офлайн
где здесь еще не хватает else?
if username == dbuser : while True: password = getpass.getpass(prompt="Enter secret password:") if (hashlib.sha1(password.encode()).hexdigest() == dbpass): print("Authentication success") break else: print("Bad password") t -= 1 if t > 0: print('Left attempts=>', t) else: print('System will reboot now...') time.sleep(3) # os.system("reboot") break else: print ("please try another username. This username is incorrect") continue break
Офлайн
Офлайн
и что из этого следует? у меня так указано:
else: print ("please try another username. This username is incorrect") continue break
Офлайн
это не считая что второе if t > 0: не понятно для чего
Офлайн
#!/usr/bin/env python3.8 import getpass import pymysql import hashlib import uuid import re import time import pyinputplus as pyip import os from uuid import getnode as mac t = 4 print("-------------------------") print("<<<<<<<<<Welcome>>>>>>>>>") print("-------------------------") print("Please enter a username (after 3 unlucky attempts system will reboot)") while True: t -= 1 if t > 0: username = pyip.inputNum('Username (must be 12 numbers): ', min=111111111111, max=999999999999, limit=3) db = pymysql.connect("hostname","user","pass","db") # prepare a cursor object using cursor() method cursor = db.cursor() cursor.execute("SELECT userID, password from permissions") data = cursor.fetchone() dbuser, dbpass = data #dbuser, dbpass = str(data[0]), data[1] # disconnect from server db.close() if username == dbuser : while True: password = getpass.getpass(prompt="Enter secret password:") if (hashlib.sha1(password.encode()).hexdigest() == dbpass): print("Authentication success") break else: print("Bad password") t -= 1 if t > 0: print('Left attempts=>', t) else: print('System will reboot now...') time.sleep(3) #os.system("reboot") break else: print ("please try another username. This username is incorrect") continue break else: print('вот здеся обработка первого if')
Отредактировано AD0DE412 (Окт. 29, 2020 15:10:29)
Офлайн
AD0DE412для того, чтобы и username и пароль спрашивало по 3 раза, дальше выполнялся бы reboot машины…
это не считая что второе if t > 0: не понятно для чего
Офлайн