generate-password can be an external program

This commit is contained in:
boyska 2022-05-20 18:30:44 +02:00
parent d0b372bcef
commit 2283d3867f
2 changed files with 17 additions and 4 deletions

3
contrib/generate_password.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
shuf -n4 /usr/share/dict/words | tr '\n' . | head -c -1

View file

@ -4,7 +4,7 @@ import random
import logging
import json
import uuid
from subprocess import Popen, CalledProcessError
from subprocess import Popen, CalledProcessError, check_output
from typing import Optional
import redis
@ -21,11 +21,15 @@ class Settings(BaseSettings):
app_name: str = "tResetter"
validate_login_exe: str
change_password_exe: str
generate_password: Optional[str]
redis_host: str = "localhost"
expire_time: int = 60 * 20
root_path: Optional[str]
root_prefix: str = "/tresetter"
class Config:
pass
@property
def redis_params(self):
return {"host": self.redis_host}
@ -125,9 +129,15 @@ def validate(username, password):
return p.returncode == 0
def password_generate():
symbols = list(string.ascii_lowercase) + list(string.digits)
return "".join(random.choices(symbols, k=10))
def password_generate() -> str:
if settings.generate_password:
s = check_output([settings.generate_password], encoding='utf8')
assert type(s) is str
return s.strip()
else:
symbols = list(string.ascii_lowercase) + list(string.digits)
return "".join(random.choices(symbols, k=10))
def change_password(username: str, new_password: str) -> bool: