34 lines
888 B
Python
Executable File
34 lines
888 B
Python
Executable File
import bcrypt
|
|
import sys
|
|
|
|
def generate_htpasswd(username, password):
|
|
# Generate a salt
|
|
salt = bcrypt.gensalt()
|
|
|
|
# Hash the password with the generated salt
|
|
hashed_password = bcrypt.hashpw(password.encode('utf-8'), salt)
|
|
|
|
# Format the string for the .htpasswd
|
|
htpasswd_string = f"{username}:{hashed_password.decode('utf-8')}"
|
|
|
|
return htpasswd_string
|
|
|
|
def main():
|
|
# Check if the correct number of arguments are provided
|
|
if len(sys.argv) != 3:
|
|
print("Usage: python script.py <username> <password>")
|
|
sys.exit(1)
|
|
|
|
# Get the username and password from the command-line arguments
|
|
username = sys.argv[1]
|
|
password = sys.argv[2]
|
|
|
|
# Generate the htpasswd string
|
|
htpasswd_string = generate_htpasswd(username, password)
|
|
|
|
# Print the htpasswd string to stdout
|
|
print(htpasswd_string)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|