authentik.core.management.commands.hash_password

Hash password using Django's password hashers

 1"""Hash password using Django's password hashers"""
 2
 3from django.contrib.auth.hashers import make_password
 4from django.core.management.base import BaseCommand, CommandError
 5
 6
 7class Command(BaseCommand):
 8    """Hash a password using Django's password hashers"""
 9
10    help = "Hash a password for use with AUTHENTIK_BOOTSTRAP_PASSWORD_HASH"
11
12    def add_arguments(self, parser):
13        parser.add_argument(
14            "password",
15            type=str,
16            help="Password to hash",
17        )
18
19    def handle(self, *args, **options):
20        password = options["password"]
21
22        if not password:
23            raise CommandError("Password cannot be empty")
24        try:
25            hashed = make_password(password)
26            self.stdout.write(hashed)
27        except ValueError as exc:
28            raise CommandError(f"Error hashing password: {exc}") from exc
class Command(django.core.management.base.BaseCommand):
 8class Command(BaseCommand):
 9    """Hash a password using Django's password hashers"""
10
11    help = "Hash a password for use with AUTHENTIK_BOOTSTRAP_PASSWORD_HASH"
12
13    def add_arguments(self, parser):
14        parser.add_argument(
15            "password",
16            type=str,
17            help="Password to hash",
18        )
19
20    def handle(self, *args, **options):
21        password = options["password"]
22
23        if not password:
24            raise CommandError("Password cannot be empty")
25        try:
26            hashed = make_password(password)
27            self.stdout.write(hashed)
28        except ValueError as exc:
29            raise CommandError(f"Error hashing password: {exc}") from exc

Hash a password using Django's password hashers

help = 'Hash a password for use with AUTHENTIK_BOOTSTRAP_PASSWORD_HASH'
def add_arguments(self, parser):
13    def add_arguments(self, parser):
14        parser.add_argument(
15            "password",
16            type=str,
17            help="Password to hash",
18        )

Entry point for subclassed commands to add custom arguments.

def handle(self, *args, **options):
20    def handle(self, *args, **options):
21        password = options["password"]
22
23        if not password:
24            raise CommandError("Password cannot be empty")
25        try:
26            hashed = make_password(password)
27            self.stdout.write(hashed)
28        except ValueError as exc:
29            raise CommandError(f"Error hashing password: {exc}") from exc

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