通过sqlalchemy,psycopg2连接到postgres时,如何不以明文形式显示密码?

编程入门 行业动态 更新时间:2024-10-28 04:19:18
本文介绍了通过sqlalchemy,psycopg2连接到postgres时,如何不以明文形式显示密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我当前正在从Python脚本连接到Postgres数据库,并且正在使用使用psycopg2的SQL炼金术:

I'm currently connecting to a Postgres db from a Python script and I'm using sqlalchemy with psycopg2:

postgresql+psycopg2://user:password@host:port/dbname[?key=value&key=value...]

该Python脚本可供用户使用,并且密码以明文显示。我该如何使用加密密码呢?

This Python script is available to users, and the password is shown in clear text. How can I use an encrypted password instead?

推荐答案

通常,这是通过几种不同的方式完成的。

Generally, this is done in a few different ways.

基本上,不要让用户直接访问该数据库。提供诸如REST API之类的接口或类似的接口,供用户与数据库进行交互。用户名和密码仅存储在服务器端。

Basically, don't make the database directly accessible to users. Provide an interface like a REST API or something similar for users to interact with the database. The username and password are only stored on the server side.

您的postgres数据库可以有多个用户。不要给他们数据库所有者的用户名和密码。只需创建一个特权较少的用户(也许是只读用户)并分发该用户和密码即可。

Your postgres database can have multiple users. Don't give them the user and password for the db owner. Just create a user with less privileges (read-only maybe?) and distribute that user and password.

更多推荐

通过sqlalchemy,psycopg2连接到postgres时,如何不以明文形式显示密码?

本文发布于:2023-10-23 06:25:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520053.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:明文   不以   连接到   形式   密码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!