from django.db import models
from hashlib import sha256
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin, UserManager
from django.utils.crypto import get_random_string, constant_time_compare
import re


class Avatar(models.Model):
    link = models.TextField('Ссылка')
    file = models.ImageField('Файл')


class Pictures(models.Model):
    link = models.TextField('Ссылка')
    file = models.ImageField('Файл')
    user_id = models.ForeignKey('users.User', null=True, on_delete=models.
        CASCADE)


class User(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField('Имя', max_length=50)
    last_name = models.CharField('Фамилия', max_length=50)
    birth_date = models.DateField('Дата рождения', null=True)
    sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F',
        'Female')))
    email = models.CharField('Электронная почта', max_length=64, null=True,
        default=None, blank=True, unique=True)
    password = models.CharField(max_length=64)
    salt = models.CharField(max_length=64)
    USERNAME_FIELD = 'email'
    EMAIL_FIELD = 'email'
    objects = UserManager()

    def set_password(self, raw_password):
        salt = get_random_string(64)
        hasher = sha256()
        raw_password = raw_password + '_' + salt
        hasher.update(raw_password.encode('utf-8'))
        self.salt = salt
        self.password = hasher.hexdigest()
        return self

    def check_password(self, raw_password):
        hasher = sha256()
        raw_password = raw_password + '_' + self.salt
        hasher.update(raw_password.encode('utf-8'))
        result = constant_time_compare(hasher.hexdigest(), self.password)
        return result

4886fad8e437b0ebb5d574ed9c63f7f0df5a2308
<mask token>


class Pictures(models.Model):
    link = models.TextField('Ссылка')
    file = models.ImageField('Файл')
    user_id = models.ForeignKey('users.User', null=True, on_delete=models.
        CASCADE)


class User(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField('Имя', max_length=50)
    last_name = models.CharField('Фамилия', max_length=50)
    birth_date = models.DateField('Дата рождения', null=True)
    sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F',
        'Female')))
    email = models.CharField('Электронная почта', max_length=64, null=True,
        default=None, blank=True, unique=True)
    password = models.CharField(max_length=64)
    salt = models.CharField(max_length=64)
    USERNAME_FIELD = 'email'
    EMAIL_FIELD = 'email'
    objects = UserManager()

    def set_password(self, raw_password):
        salt = get_random_string(64)
        hasher = sha256()
        raw_password = raw_password + '_' + salt
        hasher.update(raw_password.encode('utf-8'))
        self.salt = salt
        self.password = hasher.hexdigest()
        return self

    def check_password(self, raw_password):
        hasher = sha256()
        raw_password = raw_password + '_' + self.salt
        hasher.update(raw_password.encode('utf-8'))
        result = constant_time_compare(hasher.hexdigest(), self.password)
        return result

<mask token>


class Avatar(models.Model):
    <mask token>
    <mask token>


class Pictures(models.Model):
    link = models.TextField('Ссылка')
    file = models.ImageField('Файл')
    user_id = models.ForeignKey('users.User', null=True, on_delete=models.
        CASCADE)


class User(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField('Имя', max_length=50)
    last_name = models.CharField('Фамилия', max_length=50)
    birth_date = models.DateField('Дата рождения', null=True)
    sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F',
        'Female')))
    email = models.CharField('Электронная почта', max_length=64, null=True,
        default=None, blank=True, unique=True)
    password = models.CharField(max_length=64)
    salt = models.CharField(max_length=64)
    USERNAME_FIELD = 'email'
    EMAIL_FIELD = 'email'
    objects = UserManager()

    def set_password(self, raw_password):
        salt = get_random_string(64)
        hasher = sha256()
        raw_password = raw_password + '_' + salt
        hasher.update(raw_password.encode('utf-8'))
        self.salt = salt
        self.password = hasher.hexdigest()
        return self

    def check_password(self, raw_password):
        hasher = sha256()
        raw_password = raw_password + '_' + self.salt
        hasher.update(raw_password.encode('utf-8'))
        result = constant_time_compare(hasher.hexdigest(), self.password)
        return result

<mask token>


class Avatar(models.Model):
    link = models.TextField('Ссылка')
    file = models.ImageField('Файл')


class Pictures(models.Model):
    link = models.TextField('Ссылка')
    file = models.ImageField('Файл')
    user_id = models.ForeignKey('users.User', null=True, on_delete=models.
        CASCADE)


class User(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField('Имя', max_length=50)
    last_name = models.CharField('Фамилия', max_length=50)
    birth_date = models.DateField('Дата рождения', null=True)
    sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F',
        'Female')))
    email = models.CharField('Электронная почта', max_length=64, null=True,
        default=None, blank=True, unique=True)
    password = models.CharField(max_length=64)
    salt = models.CharField(max_length=64)
    USERNAME_FIELD = 'email'
    EMAIL_FIELD = 'email'
    objects = UserManager()

    def set_password(self, raw_password):
        salt = get_random_string(64)
        hasher = sha256()
        raw_password = raw_password + '_' + salt
        hasher.update(raw_password.encode('utf-8'))
        self.salt = salt
        self.password = hasher.hexdigest()
        return self

    def check_password(self, raw_password):
        hasher = sha256()
        raw_password = raw_password + '_' + self.salt
        hasher.update(raw_password.encode('utf-8'))
        result = constant_time_compare(hasher.hexdigest(), self.password)
        return result

from django.db import models
from hashlib import sha256
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin, UserManager
from django.utils.crypto import get_random_string, constant_time_compare
import re


class Avatar(models.Model):
    link = models.TextField('Ссылка')
    file = models.ImageField('Файл')


class Pictures(models.Model):
    link = models.TextField('Ссылка')
    file = models.ImageField('Файл')
    user_id = models.ForeignKey('users.User', null=True, on_delete=models.
        CASCADE)


class User(AbstractBaseUser, PermissionsMixin):
    first_name = models.CharField('Имя', max_length=50)
    last_name = models.CharField('Фамилия', max_length=50)
    birth_date = models.DateField('Дата рождения', null=True)
    sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F',
        'Female')))
    email = models.CharField('Электронная почта', max_length=64, null=True,
        default=None, blank=True, unique=True)
    password = models.CharField(max_length=64)
    salt = models.CharField(max_length=64)
    USERNAME_FIELD = 'email'
    EMAIL_FIELD = 'email'
    objects = UserManager()

    def set_password(self, raw_password):
        salt = get_random_string(64)
        hasher = sha256()
        raw_password = raw_password + '_' + salt
        hasher.update(raw_password.encode('utf-8'))
        self.salt = salt
        self.password = hasher.hexdigest()
        return self

    def check_password(self, raw_password):
        hasher = sha256()
        raw_password = raw_password + '_' + self.salt
        hasher.update(raw_password.encode('utf-8'))
        result = constant_time_compare(hasher.hexdigest(), self.password)
        return result
