Artifact 69e626c63b88fbb4fa1c2e29b6bb9f21ce01d6e71226d66fd3f6be8376fa773d:
- File
backend/src/swiftflow_crypto_ffi.erl
— part of check-in
[1821522f51]
at
2026-10-23 05:51:23
on branch trunk
— RBAC 权限与多仓数据隔离
- 新增用户、角色、权限点、用户角色、用户授权仓库、登录会话、审计日志表(008_rbac) - 预设五个角色(超级管理员、仓库主管、制单/调度员、打包复核员、库内作业员),按角色限制登录终端 - 账号密码登录,PBKDF2-SHA256 加盐存储,令牌只存哈希,会话按配置过期,连续输错锁定 - 首个超级管理员从 SWIFTFLOW_ADMIN_USERNAME / SWIFTFLOW_ADMIN_PASSWORD 创建,仅在用户表为空时生效 - 除健康检查与登录外所有接口需登录并校验权限点 - 订单、采购单、库位、库存、批次码按授权仓库过滤;收货、上架、出库只能在当前作业仓库进行 - 用户管理、角色查询、审计日志接口;同步、库位、上架、收货、出库写操作记录审计 (user: pluto size: 713)
-module(swiftflow_crypto_ffi). -export([random_hex/1, sha256_hex/1, pbkdf2_sha256_hex/3, secure_equals/2]). random_hex(Bytes) when is_integer(Bytes), Bytes > 0 -> binary:encode_hex(crypto:strong_rand_bytes(Bytes), lowercase). sha256_hex(Data) when is_binary(Data) -> binary:encode_hex(crypto:hash(sha256, Data), lowercase). pbkdf2_sha256_hex(Password, Salt, Iterations) when is_binary(Password), is_binary(Salt), is_integer(Iterations), Iterations > 0 -> binary:encode_hex(crypto:pbkdf2_hmac(sha256, Password, Salt, Iterations, 32), lowercase). secure_equals(A, B) when is_binary(A), is_binary(B), byte_size(A) =:= byte_size(B) -> crypto:hash_equals(A, B); secure_equals(_, _) -> false.