forked from wg-easy/wg-easy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'wg-easy/master'
- Loading branch information
Showing
17 changed files
with
376 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,28 @@ | ||
<!-- created by Mathys Lopinto (@mathys-lopinto) --> | ||
# How to generate bcrypt hash | ||
# wg-password | ||
|
||
## Prerequisites | ||
- Python 3 | ||
- bcrypt library | ||
`wg-password` (wgpw) is a script that generates bcrypt password hashes for use with `wg-easy`, enhancing security by requiring passwords. | ||
|
||
## Prerequisites Installation | ||
### Windows | ||
Download and install Python 3 from [official website](https://www.python.org/downloads/). | ||
Check "Add python.exe to PATH" before running "Install Now". | ||
## Features | ||
|
||
Open Command Prompt (win + r, type "cmd" and press enter) and run the following command to install bcrypt library: | ||
```bash | ||
pip install bcrypt | ||
``` | ||
|
||
### Debian based distributions | ||
```bash | ||
sudo apt-get update | ||
sudo apt-get install python3 python3-pip | ||
# If you use have install python using apt | ||
sudo apt-get install python3-bcrypt | ||
# If don't install python using apt | ||
pip3 install bcrypt | ||
# If you got externally-managed-environment error | ||
pip3 install bcrypt --break-system-packages | ||
``` | ||
|
||
### Fedora based distributions | ||
```bash | ||
sudo dnf update | ||
sudo dnf install python3 python3-pip | ||
# If you use have install python using dnf | ||
sudo dnf install python3-bcrypt | ||
# If don't install python using dnf | ||
pip3 install bcrypt | ||
# If you got externally-managed-environment error | ||
pip3 install bcrypt --break-system-packages | ||
``` | ||
|
||
### Arch Linux based distributions | ||
```bash | ||
sudo pacman -Syy | ||
sudo pacman -S python python-pip | ||
# If you use have install python using pacman | ||
sudo pacman -S python-bcrypt | ||
# If don't install python using pacman | ||
pip3 install bcrypt | ||
# If you got externally-managed-environment error | ||
pip3 install bcrypt --break-system-packages | ||
``` | ||
- Generate bcrypt password hashes. | ||
- Easily integrate with `wg-easy` to enforce password requirements. | ||
|
||
## Generating bcrypt hash from the command line | ||
You can use the following one-liner command to generate a bcrypt hash directly in the cmd/ terminal: | ||
```bash | ||
python3 -c "import bcrypt; password = b'your_password_here'; assert len(password) < 72, 'Password must be less than 72 bytes due to bcrypt limitation'; hashed = bcrypt.hashpw(password, bcrypt.gensalt()); print(f'The hashed password is: {hashed.decode()}'); docker_interpolation = hashed.decode().replace('$', '$$'); print(f'The hashed password for a Docker env is: {docker_interpolation}')" # or python if you run this on Windows. CHANGE your_password_here BY YOUR PASSWORD | ||
``` | ||
Please change ``your_password_here`` in the line by your own password. | ||
|
||
## Generating bcrypt hash from an script file | ||
### Do not name the file `bcrypt.py` as it will cause an error. | ||
Create a python file with the following content: | ||
```python | ||
import bcrypt | ||
|
||
# Initial password | ||
password = b"your_password_here" # DO NOT REMOVE THE b | ||
|
||
# Assert that the password is under 72 bytes | ||
assert len(password) < 72, "Password must be less than 72 bytes due to bcrypt limitation" | ||
|
||
# Generate a salt and hash the password | ||
hashed = bcrypt.hashpw(password, bcrypt.gensalt()) | ||
## Usage with Docker | ||
|
||
# Print the hashed password | ||
print(f'The hashed password is: {hashed.decode()}') | ||
To generate a bcrypt password hash using docker, run the following command : | ||
|
||
# Prepare the hashed password for Docker environment variables | ||
docker_interpolation = hashed.decode().replace("$", "$$") | ||
print(f'The hashed password for a Docker env is: {docker_interpolation}') | ||
```sh | ||
docker run ghcr.io/wg-easy/wg-easy wgpw YOUR_PASSWORD | ||
PASSWORD_HASH='$2b$12$coPqCsPtcFO.Ab99xylBNOW4.Iu7OOA2/ZIboHN6/oyxca3MWo7fW' // litteraly YOUR_PASSWORD | ||
``` | ||
|
||
Replace `your_password_here` with the password you want to hash. | ||
*Important* : make sure to enclose your password in single quotes when you run `docker run` command : | ||
|
||
Run the python file and you will get the hashed password. | ||
|
||
## Get the right hash | ||
Copy the 2nd line of the output (after the : ) and use it as your hashed password. | ||
|
||
__Exemple__ | ||
If the output is: | ||
```txt | ||
The hashed password is: $2b$12$NRiL4Kw4dKid.ix2WvZltOmaQBZjoX30shjHJXRVdEGshAxYWXXMe | ||
The hashed password for an docker env is: $$2b$$12$$NRiL4Kw4dKid.ix2WvZltOmaQBZjoX30shjHJXRVdEGshAxYWXXMe | ||
``` | ||
|
||
The docker line ``PASSWORD_HASH`` will be: | ||
```txt | ||
PASSWORD_HASH=$$2b$$12$$NRiL4Kw4dKid.ix2WvZltOmaQBZjoX30shjHJXRVdEGshAxYWXXMe | ||
``` | ||
```bash | ||
$ echo $2b$12$coPqCsPtcF | ||
b2 | ||
$ echo "$2b$12$coPqCsPtcF" | ||
b2 | ||
$ echo '$2b$12$coPqCsPtcF' | ||
$2b$12$coPqCsPtcF | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
{ | ||
"version": "1.0.1", | ||
"scripts": { | ||
"sudobuild": "DOCKER_BUILDKIT=1 sudo docker build --tag wg-easy-m3 .", | ||
"build": "DOCKER_BUILDKIT=1 docker build --tag wg-easy-m3 .", | ||
"serve": "docker compose -f docker-compose.yml -f docker-compose.dev.yml up", | ||
"sudostart": "sudo docker run --env WG_HOST=0.0.0.0 --name wg-easy-m3 --cap-add=NET_ADMIN --cap-add=SYS_MODULE --sysctl=\"net.ipv4.conf.all.src_valid_mark=1\" --mount type=bind,source=\"$(pwd)\"/config,target=/etc/wireguard -p 51820:51820/udp -p 51821:51821/tcp wg-easy-m3", | ||
"start": "docker run --env WG_HOST=0.0.0.0 --name wg-easy-m3 --cap-add=NET_ADMIN --cap-add=SYS_MODULE --sysctl=\"net.ipv4.conf.all.src_valid_mark=1\" --mount type=bind,source=\"$(pwd)\"/config,target=/etc/wireguard -p 51820:51820/udp -p 51821:51821/tcp wg-easy-m3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.