Advertisement
Guest User

Untitled

a guest
Nov 1st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import time
  2. # constants
  3. FIVE_MINUTE = 5 * 60 # second
  4. FIVE_SECOND = 5 # second
  5.  
  6. # TIME_BUFFER = FIVE_MINUTE
  7. TIME_BUFFER = FIVE_SECOND
  8. # pake 5 detik aja buat ngetestnya biar gampang.
  9. # kalo mau 5 menit, ganti jadi TIME_BUFFER = FIVE_MINUTE
  10.  
  11. # states
  12. user = {"name": "Nama User", "password": "test123" }
  13. session = {"iterationCount": 0, "lastEntryTime": 0 }
  14.  
  15. def main():
  16.   while(True):
  17.     password = raw_input('masukan password: ')
  18.     # check kalo udah boleh nyoba password baru atau belom
  19.     if(session["lastEntryTime"] + TIME_BUFFER > time.time()):
  20.       print("anda belum boleh mencoba lagi sampai")
  21.     elif(password == user["password"]):
  22.       print('password sudah benar')
  23.       print("program selesai")
  24.       break
  25.     else:
  26.       print("password salah")
  27.       session["lastEntryTime"] = time.time()
  28.       session["iterationCount"] = session["iterationCount"] + 1 # ngga penting sih.
  29.  
  30. if __name__ == '__main__':
  31.   main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement