duzhuo's-blog

学无止境

数据库中加密存储密码和验证密码的步骤

以下内容来自ChatGLM

存储密码

  1. 生成盐(Salt)
    • 为每个用户生成一个随机盐。
  2. 密码与盐结合
    • 将用户密码与盐值结合。
  3. 加密
    • 使用上述算法对结合后的密码进行加密。
  4. 存储
    • 将加密后的密码(哈希值)和盐存储在数据库中。

验证密码

  1. 从数据库中取出盐和哈希值

    • 在用户尝试登录时,系统需要从数据库中检索与该用户账户关联的盐值和之前存储的哈希密码。
  2. 使用相同的算法和盐对用户输入的密码进行加密

    • 将用户输入的密码与从数据库中取出的盐值结合,然后使用相同的加密算法对结合后的密码进行加密。
  3. 比较加密后的值与数据库中的哈希值是否相同

    • 将新计算出的哈希值与数据库中存储的哈希值进行比较。如果两者匹配,说明用户输入的密码正确;如果不匹配,说明密码错误。

关于盐:

内容来自 https://www.cnblogs.com/xjnotxj/p/12716981.html

  • 盐不能太短
  • 盐不能重复使用(否则一破解,所有的都遭殃)
  • 盐随机变化(例如,虽用户名不重复,但用户名不能拿来当盐)

TypeScript 代码实现

阅读全文 »

前两天尝试写一个给jellyfin服务器添加演员信息的程序,读issue和参考别人的代码的时候发现很多验证的步骤比较过时,故自己写一点留档参考。

swagger api文档 http://localhost:8096/api-docs/swagger

在请求头添加验证 https://gist.github.com/nielsvanvelzen/ea047d9028f676185832e51ffaf12a6f

服务端创建api密钥 http://localhost:8096/web/#/dashboard/keys

userId获取 http://localhost:8096/web/#/dashboard/users 点击你想获得userId的用户并在url的query部分查看

例如 http://192.168.2.202:8096/web/#/dashboard/users/profile?userId=99e7058d92d34f74bd369728f432a0e2

代码参考

import requests
import json

jellyfin_apiKey = "3287930a2ab9422eaa6e1dc4a5f23c24"
jellyfin_host = "http://192.168.2.202:8096"
jellyfin_userId = "99e7058d92d34f74bd369728f432a0e2"

jellyfin_headers = {
    'accept': '*/*',
    "Authorization": f'MediaBrowser Token="{jellyfin_apiKey}"',
    "Content-Type": "application/json",
}

# 获取全部演员信息,返回json
response = requests.get(f'{jellyfin_host}/Persons?userId={jellyfin_userId}',headers=jellyfin_headers)
dict = response.json()
print(dict)

# 获取单个演员信息
actor_name = '波多野結衣'
response = requests.get(f'{jellyfin_host}/Persons/{actor_name}?userId={jellyfin_userId}',headers=jellyfin_headers)
dict = response.json()
print(dict)
# 修改演员Overview并提交
actor_id = dict["Id"]
# Overview支持html标签
dict["Overview"] = """1988年5月24日生まれ<br>
身長<b>163cm</b><br>
<b>B88cm</b><br>
<b>W59cm</b><br>
<b>H85cm</b><br>
ブラ <b>Eカップ</b>"""
response = requests.post(f'{jellyfin_host}/Items/{actor_id}?userId={jellyfin_userId}', headers=jellyfin_headers,json=dict)
# 成功返回204
print(response.status_code)

喜报 openssh远程代码执行漏洞CVE-2024-6387 Debian发行版已经全部修补

Screenshot_20240704_081856.png

注意: 有些使用DD重装脚本安装的Debian bookworm 没有开启 bookworm-security源,需要手动开启。

前言

Ubuntu发行版的终端广告(Bug #1950692)和snap(Mint Blog中的观点)一直是令人诟病的内容,也是我切换到Debian的原因。

但是,今天还是要注册一下Ubuntu Pro,毕竟还有一些以前安装的机器在运行着已经EOL的Ubuntu版本,需要安装一些安全补丁。

pic

操作

打开Ubuntu Pro的网站 https://ubuntu.com/pro

点击Get Ubuntu Pro now并选择Myself,点击Register登录帐号确认。

获取Token,复制下面的命令。

Screenshot_20240702_201037-1.png

这里以**Ubuntu 18.04 LTS (Bionic Beaver)**为例:

阅读全文 »

在查看Python代码中,经常会看到类似这样的代码:

# module.py
def example() -> None:
    print("This is an example.")

if __name__ == '__main__':
    example()

这里直接运行文件可以获得输出内容:

$ python3 module.py
This is an example.

现在我们在另一个文件中将module.py作为模块导入并运行:

# main.py
from module import example

example()
$ python3 main.py
This is an example.

我们修改module.py文件,在测试中我们经常会这么写:

# module.py
def example() -> None:
    print("This is an example.")

example()

分别运行module.py main.py

阅读全文 »

错误提示

Traceback (most recent call last):
  File "/home/duzhuo/src/scraper-test/.venv/bin/sqlacodegen", line 5, in <module>
    from sqlacodegen.main import main
  File "/home/duzhuo/src/scraper-test/.venv/lib/python3.11/site-packages/sqlacodegen/main.py", line 11, in <module>
    from sqlacodegen.codegen import CodeGenerator
  File "/home/duzhuo/src/scraper-test/.venv/lib/python3.11/site-packages/sqlacodegen/codegen.py", line 9, in <module>
    from inspect import ArgSpec
ImportError: cannot import name 'ArgSpec' from 'inspect' (/usr/lib/python3.11/inspect.py)

来自GPT的错误分析:您遇到的错误消息是由于 inspect.ArgSpec 类在 Python 3.11 中被移除了。ArgSpec 类在 Python 3.5 中已被弃用,并在 Python 3.11 中被移除。

当前使用的sqlacodegen版本为2.3.0.post1。是pypi上面的默认release版本。

解决方法

编辑 .venv/lib/python3.11/site-packages/sqlacodegen/codegen.py

找到from inspect import ArgSpec替换成from inspect import FullArgSpec as ArgSpec

或者升级sqlacodegen版本到3.0.0 rc3以上。来源:https://github.com/agronholm/sqlacodegen/issues/239#issuecomment-1871370700

0%