chkpass
数据类型:自动加密的密码
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
chkpass | 1.0 | TYPE | PostgreSQL | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 3920 | chkpass | 否 | 是 | 否 | 是 | 否 | 否 | - |
| 相关扩展 | prefix semver unit pgpdf pglite_fusion md5hash asn1oid roaringbitmap |
|---|
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 | 1817161514 | chkpass | - |
| RPM | PIGSTY | 1.0 | 1817161514 | chkpass_$v | - |
| DEB | PIGSTY | 1.0 | 1817161514 | postgresql-$v-chkpass | - |
构建
您可以使用 pig build 命令构建 chkpass 扩展的 RPM / DEB 包:
pig build pkg chkpass # 构建 RPM / DEB 包
安装
您可以直接安装 chkpass 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install chkpass; # 当前活跃 PG 版本安装
pig ext install -y chkpass -v 18 # PG 18
pig ext install -y chkpass -v 17 # PG 17
pig ext install -y chkpass -v 16 # PG 16
pig ext install -y chkpass -v 15 # PG 15
pig ext install -y chkpass -v 14 # PG 14
dnf install -y chkpass_18 # PG 18
dnf install -y chkpass_17 # PG 17
dnf install -y chkpass_16 # PG 16
dnf install -y chkpass_15 # PG 15
dnf install -y chkpass_14 # PG 14
apt install -y postgresql-18-chkpass # PG 18
apt install -y postgresql-17-chkpass # PG 17
apt install -y postgresql-16-chkpass # PG 16
apt install -y postgresql-15-chkpass # PG 15
apt install -y postgresql-14-chkpass # PG 14
创建扩展:
CREATE EXTENSION chkpass;
用法
chkpass 扩展提供了一种用于存储加密密码的数据类型。该类型最初随 PostgreSQL 一起发布(在 PG 11 中移除),这是适用于现代 PostgreSQL 的独立版本。
CREATE EXTENSION chkpass;
数据类型
chkpass 类型在输入时使用 Unix crypt() 自动加密密码,仅存储加密后的形式。
CREATE TABLE accounts (
username text PRIMARY KEY,
password chkpass
);
INSERT INTO accounts VALUES ('admin', 'mysecretpassword');
运算符
= 运算符用于将明文密码与存储的加密值进行比对:
SELECT * FROM accounts WHERE password = 'mysecretpassword';
-- 如果密码正确则返回匹配行
行为特性
- 密码在输入时自动加密——明文永远不会被存储
- 输出显示加密后的哈希值,而非原始密码
=比较会先加密右侧操作数,然后比较哈希值- 使用标准 Unix
crypt()函数进行加密