鱼C论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: 小甲鱼

[知识点备忘] 第041讲:函数(I)

[复制链接]
发表于 2023-2-5 15:55:17 | 显示全部楼层
侯星无常 发表于 2023-2-5 11:16
def div(x,y):
    if y == 0:
        return 'a'

没有
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2023-2-6 07:44:57 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-4-12 18:29:37 | 显示全部楼层
终于进入主题了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-6-18 18:57:08 | 显示全部楼层
打卡~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-3-11 21:44:00 | 显示全部楼层
打卡
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-3-17 11:46:36 | 显示全部楼层
打卡
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-10-8 22:05:49 | 显示全部楼层
老师好!在38讲解课后作业使用:hashlib.md5(bytes(password, "utf-8"))存储密码正常的,为什么用了函数之后,同样的字符串传入后哈希值不一样,但是使用hashlib.md5(bytes(password, "utf-8")).hexdigest()存储又是正常的,麻烦解答一下,谢谢!
  1. import hashlib   
  2. print("欢迎来到鱼C论坛~")
  3. print("=" * 50)
  4. user = {}

  5. def get_int():
  6.      print("1. 注册")
  7.      print("2. 登录")
  8.      print("3. 退出")
  9.      command = input("请输入指令:")
  10.      print("=" * 50)
  11.      match command:
  12.         case "1":
  13.             register()
  14.             
  15.         case "2":
  16.             login()

  17.         case "3":
  18.             return 1
  19. def register():
  20.      name = input("请输入用户名:")
  21.      while name in user:
  22.           print("用户名已注册!")
  23.           name = input("请重新输入用户名: ")
  24.      password = input("请输入密码:")
  25.      while not password:
  26.           print("密码为空,请重新输入!")
  27.      password = encrypt(password)
  28.      user[name] = password
  29.      print(f"注册时的密码:{user[name]}")
  30.      print("恭喜,注册成功~")
  31.      print("=" * 50)
  32.      
  33. def encrypt(password):
  34.      hash_password = hashlib.md5(bytes(password, "utf-8"))
  35.      print(f"原始密码 = {password}, 哈希密码 = {hash_password}, 密码长度 = {len(password)}")
  36.      return hash_password
  37.      

  38. def login():
  39.      name = input("请输入用户名:")
  40.      while name not in user:
  41.           print("该用户名不存在!")
  42.           name = input("请重新输入用户名:")
  43.          
  44.      password =input("请输入密码:")
  45.      password = encrypt(password)
  46.      print(f"登陆的哈希密码:{password}")
  47.      while user[name] != password:
  48.           print("密码错误!")
  49.           password = input("请重新输入密码:")
  50.           password = encrypt(password)
  51.      else:
  52.           print("恭喜,登录成功~")
  53.           print("=" * 50)
  54.          
  55.          
  56. while True:
  57.      if get_int():
  58.           break
  59.          
复制代码

登录和注册输入密码一样,哈希值不一样

登录和注册输入密码一样,哈希值不一样

原代码

原代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 00:17

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表