Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Password Field in Model Django

I want to create password as password field in views.

models.py:

class User(models.Model):     username = models.CharField(max_length=100)     password = models.CharField(max_length=50) 

forms.py:

class UserForm(ModelForm):     class Meta:         model = User 
like image 262
Hemanth S R Avatar asked Jul 08 '13 09:07

Hemanth S R


People also ask

Is there password field in Django models?

The Django's Forms The above form has two inputs - a text field named username (the name attribute in the html input field is what determines the name of input field) and a password field named password - and a submit button. The form uses POST method to submit form data to server.

How are passwords stored in Django?

Django provides a flexible password storage system and uses PBKDF2 by default. Those are the components used for storing a User's password, separated by the dollar-sign character and consist of: the hashing algorithm, the number of algorithm iterations (work factor), the random salt, and the resulting password hash.

What is Onetoone field in Django?

A one-to-one relationship. Conceptually, this is similar to a ForeignKey with unique=True , but the "reverse" side of the relation will directly return a single object. In contrast to the OneToOneField "reverse" relation, a ForeignKey "reverse" relation returns a QuerySet .


1 Answers

Use widget as PasswordInput

from django import forms class UserForm(forms.ModelForm):     password = forms.CharField(widget=forms.PasswordInput)     class Meta:         model = User 
like image 110
Akshar Raaj Avatar answered Sep 22 '22 06:09

Akshar Raaj