generate-password can be an external program
This commit is contained in:
parent
d0b372bcef
commit
2283d3867f
2 changed files with 17 additions and 4 deletions
3
contrib/generate_password.sh
Executable file
3
contrib/generate_password.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
shuf -n4 /usr/share/dict/words | tr '\n' . | head -c -1
|
18
tresetter.py
18
tresetter.py
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue