二手产品经理

二手产品经理

THIS IS RENO

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

Record#

  1. Today's study is about password security, salting and hashing passwords.
  2. The salt should be unique and not repeated, and each user has their own salt value.
  3. The purpose of salt is to prevent passwords from being reversed through collision, such as using a rainbow table by hackers.
  4. Hash is an algorithm, and there is also MD5.
  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.