-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from Nuno-Jesus/jwtbug
Password Validation
- Loading branch information
Showing
5 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/pong/migrations/0002_alter_gamesstats_average_ball_speed_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 5.1.3 on 2024-11-21 21:35 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('pong', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='gamesstats', | ||
name='average_ball_speed', | ||
field=models.FloatField(default=0), | ||
), | ||
migrations.AlterField( | ||
model_name='gamesstats', | ||
name='max_ball_speed', | ||
field=models.FloatField(default=0), | ||
), | ||
migrations.AlterField( | ||
model_name='gamesstats', | ||
name='min_ball_speed', | ||
field=models.FloatField(default=0), | ||
), | ||
migrations.AlterField( | ||
model_name='userstats', | ||
name='max_ball_speed', | ||
field=models.FloatField(default=0), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import re | ||
from django.core.exceptions import ValidationError | ||
from django.utils.translation import gettext as _ | ||
|
||
class CustomPasswordValidator: | ||
|
||
def validate(self, password, user): | ||
if not re.search(r'[A-Z]', password): | ||
raise ValidationError( | ||
_("Password must contain at least one uppercase letter."), | ||
code='password_no_upper', | ||
) | ||
if not re.search(r'[a-z]', password): | ||
raise ValidationError( | ||
_("Password must contain at least one lowercase letter."), | ||
code='password_no_lower', | ||
) | ||
if not re.search(r'[0-9]', password): | ||
raise ValidationError( | ||
_("Password must contain at least one digit."), | ||
code='password_no_digit', | ||
) | ||
if not re.search(r'[\W_]', password): | ||
raise ValidationError( | ||
_("Password must contain at least one special character."), | ||
code='password_no_special', | ||
) | ||
|
||
|
||
def get_help_text(self): | ||
return _( | ||
"Your password must be at least 10 characters long and contain at least one " | ||
"uppercase letter, one lowercase letter, one digit, and one special character." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters