authentik.core.management.commands.hash_password

Hash password using Django's password hashers

 1"""Hash password using Django's password hashers"""
 2
 3import sys
 4from getpass import getpass
 5
 6from django.contrib.auth.hashers import make_password
 7from django.core.management.base import BaseCommand, CommandError
 8
 9
10class Command(BaseCommand):
11    """Hash a password using Django's password hashers"""
12
13    help = (
14        "Hash a password for use with AUTHENTIK_BOOTSTRAP_PASSWORD_HASH. Prompt when "
15        "interactive, or read the password from standard input."
16    )
17
18    def handle(self, *args, **options):
19        if sys.stdin.isatty():
20            password = getpass("Password: ")
21            password_again = getpass("Password (again): ")
22            if password != password_again:
23                raise CommandError("Passwords do not match")
24        else:
25            password = input()
26
27        if not password:
28            raise CommandError("Password cannot be empty")
29        hashed = make_password(password)
30        self.stdout.write(hashed)
class Command(django.core.management.base.BaseCommand):
11class Command(BaseCommand):
12    """Hash a password using Django's password hashers"""
13
14    help = (
15        "Hash a password for use with AUTHENTIK_BOOTSTRAP_PASSWORD_HASH. Prompt when "
16        "interactive, or read the password from standard input."
17    )
18
19    def handle(self, *args, **options):
20        if sys.stdin.isatty():
21            password = getpass("Password: ")
22            password_again = getpass("Password (again): ")
23            if password != password_again:
24                raise CommandError("Passwords do not match")
25        else:
26            password = input()
27
28        if not password:
29            raise CommandError("Password cannot be empty")
30        hashed = make_password(password)
31        self.stdout.write(hashed)

Hash a password using Django's password hashers

help = 'Hash a password for use with AUTHENTIK_BOOTSTRAP_PASSWORD_HASH. Prompt when interactive, or read the password from standard input.'
def handle(self, *args, **options):
19    def handle(self, *args, **options):
20        if sys.stdin.isatty():
21            password = getpass("Password: ")
22            password_again = getpass("Password (again): ")
23            if password != password_again:
24                raise CommandError("Passwords do not match")
25        else:
26            password = input()
27
28        if not password:
29            raise CommandError("Password cannot be empty")
30        hashed = make_password(password)
31        self.stdout.write(hashed)

The actual logic of the command. Subclasses must implement this method.