quart-imp/docs/_md/v1/quart_imp_auth-generate_salt.md

47 lines
862 B
Markdown
Raw Normal View History

2024-08-16 15:09:07 +01:00
```
Menu = quart_imp.auth/generate_salt
Title = generate_salt - quart_imp.auth
```
```python
from quart_imp.auth import generate_salt
```
```python
generate_salt(length: int = 4) -> str
```
---
Generates a string of (length) characters of punctuation.
The Default length is 4.
For use in password hashing and storage of passwords in the database.
##### Example:
```python
generate_salt() # >>> '*!$%'
```
```python
@app.route('/register', methods=['GET', 'POST'])
async def register():
if request.method == "POST":
...
salt = generate_salt()
password = request.form.get('password')
encrypted_password = encrypt_password(password, salt)
...
user = User(
username=username,
email=email,
password=encrypted_password,
salt=salt
)
...
```