Skip to content

Commit f68ebac

Browse files
committed
hash_password accepts stdin now
1 parent f1a1c7f commit f68ebac

File tree

5 files changed

+216
-11
lines changed

5 files changed

+216
-11
lines changed

changelog.d/17608.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hash_password now accepts input from stdin

debian/hash_password.1

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
.\" generated with Ronn-NG/v0.8.0
2-
.\" http://github.com/apjanke/ronn-ng/tree/0.8.0
3-
.TH "HASH_PASSWORD" "1" "July 2021" "" ""
1+
.\" generated with Ronn-NG/v0.10.1
2+
.\" http://github.com/apjanke/ronn-ng/tree/0.10.1
3+
.TH "HASH_PASSWORD" "1" "August 2024" ""
44
.SH "NAME"
55
\fBhash_password\fR \- Calculate the hash of a new password, so that passwords can be reset
66
.SH "SYNOPSIS"
7-
\fBhash_password\fR [\fB\-p\fR|\fB\-\-password\fR [password]] [\fB\-c\fR|\fB\-\-config\fR \fIfile\fR]
7+
.TS
8+
allbox;
9+
\fBhash_password\fR [\fB\-p\fR \fB\-\-password\fR [password]] [\fB\-c\fR \fB\-\-config\fR \fIfile\fR]
10+
.TE
811
.SH "DESCRIPTION"
912
\fBhash_password\fR calculates the hash of a supplied password using bcrypt\.
1013
.P
@@ -20,7 +23,7 @@ bcrypt_rounds: 17 password_config: pepper: "random hashing pepper"
2023
.SH "OPTIONS"
2124
.TP
2225
\fB\-p\fR, \fB\-\-password\fR
23-
Read the password form the command line if [password] is supplied\. If not, prompt the user and read the password form the \fBSTDIN\fR\. It is not recommended to type the password on the command line directly\. Use the STDIN instead\.
26+
Read the password form the command line if [password] is supplied, or from \fBSTDIN\fR\. If not, prompt the user and read the password from the tty prompt\. It is not recommended to type the password on the command line directly\. Use the STDIN instead\.
2427
.TP
2528
\fB\-c\fR, \fB\-\-config\fR
2629
Read the supplied YAML \fIfile\fR containing the options \fBbcrypt_rounds\fR and the \fBpassword_config\fR section containing the \fBpepper\fR value\.
@@ -33,7 +36,17 @@ $2b$12$VJNqWQYfsWTEwcELfoSi4Oa8eA17movHqqi8\.X8fWFpum7SxZ9MFe
3336
.fi
3437
.IP "" 0
3538
.P
36-
Hash from the STDIN:
39+
Hash from the stdin:
40+
.IP "" 4
41+
.nf
42+
$ cat password_file | hash_password
43+
Password:
44+
Confirm password:
45+
$2b$12$AszlvfmJl2esnyhmn8m/kuR2tdXgROWtWxnX\.rcuAbM8ErLoUhybG
46+
.fi
47+
.IP "" 0
48+
.P
49+
Hash from the prompt:
3750
.IP "" 4
3851
.nf
3952
$ hash_password
@@ -53,6 +66,6 @@ $2b$12$CwI\.wBNr\.w3kmiUlV3T5s\.GT2wH7uebDCovDrCOh18dFedlANK99O
5366
.fi
5467
.IP "" 0
5568
.SH "COPYRIGHT"
56-
This man page was written by Rahul De <\fI\%mailto:rahulde@swecha\.net\fR> for Debian GNU/Linux distribution\.
69+
This man page was written by Rahul De «rahulde@swecha\.net» for Debian GNU/Linux distribution\.
5770
.SH "SEE ALSO"
5871
synctl(1), synapse_port_db(1), register_new_matrix_user(1), synapse_review_recent_signups(1)

debian/hash_password.1.html

+182
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

debian/hash_password.ronn

+10-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ A sample YAML file accepted by `hash_password` is described below:
2929
## OPTIONS
3030

3131
* `-p`, `--password`:
32-
Read the password form the command line if [password] is supplied.
33-
If not, prompt the user and read the password form the `STDIN`.
32+
Read the password form the command line if [password] is supplied, or from `STDIN`.
33+
If not, prompt the user and read the password from the tty prompt.
3434
It is not recommended to type the password on the command line
3535
directly. Use the STDIN instead.
3636

@@ -45,7 +45,14 @@ Hash from the command line:
4545
$ hash_password -p "p@ssw0rd"
4646
$2b$12$VJNqWQYfsWTEwcELfoSi4Oa8eA17movHqqi8.X8fWFpum7SxZ9MFe
4747

48-
Hash from the STDIN:
48+
Hash from the stdin:
49+
50+
$ cat password_file | hash_password
51+
Password:
52+
Confirm password:
53+
$2b$12$AszlvfmJl2esnyhmn8m/kuR2tdXgROWtWxnX.rcuAbM8ErLoUhybG
54+
55+
Hash from the prompt:
4956

5057
$ hash_password
5158
Password:

synapse/_scripts/hash_password.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def main() -> None:
5656
password_pepper = password_config.get("pepper", password_pepper)
5757
password = args.password
5858

59-
if not password:
59+
if not password and not sys.stdin.isatty():
60+
password = sys.stdin.readline().strip()
61+
elif not password:
6062
password = prompt_for_pass()
6163

6264
# On Python 2, make sure we decode it to Unicode before we normalise it

0 commit comments

Comments
 (0)