二手产品经理

二手产品经理

THIS IS RENO

Hash - 71 days - Learn Python online for 100 days.

Record#

  1. Today's study is about password security, using salt and hash for passwords.
  2. Salt should be unique and not repeated, each user has their own salt value.
  3. The purpose of salt is to prevent password cracking through rainbow table attacks.
  4. Hash is an algorithm, and md5 is also one.
  5. Today's exercise is to write a login program, which includes two functions: creating a user and user login.

CODE#

from replit import db
import random

print("🌟Login System🌟")


def AddUser():
  username = input("Username > ")
  password = input("Password > ")
  salt = random.randint(1000, 9999)
  newpass = hash(f"{password}{salt}")
  db[username] = {"password": newpass, "salt": salt}
  print("Success")


def Login():
  username = input("Username > ")
  password = input("Password > ")
  salt = db[username]["salt"]
  newpass = hash(f"{password}{salt}")
  if db[username]:
    if newpass == db[username]["password"]:
      print(f"{db[username]}, Welcome!")
    else:
      print("Sorry1")
  else:
    print("Sorry2")


while True:
  menu = input("1: Add User\n2: Login\n")
  if menu == "1":
    AddUser()
  elif menu == "2":
    Login()


Translation:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.