Password Field Not being encrypted

647 views
Skip to first unread message

raj

unread,
Aug 31, 2011, 12:05:50 AM8/31/11
to Django users
Hey guys, I'm trying to make a custom registration form for a custom
UserProfile class.
I have the following form:

class UserForm(ModelForm):
username = forms.EmailField(label = _("Email"), widget =
forms.TextInput(attrs ={ 'id':'email'}), required=True)
first_name = forms.CharField(widget = forms.TextInput(attrs =
{'id':'fname'}), required=True)
last_name = forms.CharField(widget = forms.TextInput(attrs =
{'id':'lname'}), required=True)
linked_id = forms.CharField(widget = forms.HiddenInput(attrs =
{'id':'linkedid'}))
password = forms.CharField(label=_('Password'),
widget=forms.PasswordInput(render_value = False), required = True)
password2 = forms.CharField(label=_('Re-Enter your password'), widget
= forms.PasswordInput(render_value = False))
email = forms.CharField(widget = forms.HiddenInput(), required =
False)

class Meta:
model = UserProfile
fields = ('username', 'first_name', 'last_name', 'linked_id',
'password', 'email', )

def clean_password2(self):
password1 = self.cleaned_data.get("password", "")
password2 = self.cleaned_data['password2']
if password1 != password2:
raise forms.ValidationError(_("The passwords you entered did not
match!"))
return password2

def clean_email(self):
email = self.cleaned_data['username']
return email

The issue that I'm having is that when the password is entered, and
saved, its not being encrypted. So I can just view a users password in
my admin panel...
How do I get the passwords to be encrypted? I had another website and
it worked then, but when I'm trying it now, it just isn't working.
Help please. Thank you.

Jirka Vejrazka

unread,
Aug 31, 2011, 1:10:45 AM8/31/11
to django...@googlegroups.com
Raj,

PasswordInput deals with browser forms to make sure that a password
can't be seen in the form by someone looking over user's shoulder. But
it does nothing to encrypt passwords in database.

Why don't you check out django.contrib.auth.models for inspiration
about encrypting passwords if plan on doing it yourself and not
reusing the standard auth framework?

Cheers

Jirka

lokesh

unread,
Aug 31, 2011, 10:22:47 AM8/31/11
to Django users
hi,
Use set_password method from django contrib auth models in your
custom model. while saving your custom form pass the password to set
password method and save returned encrypted password in your model.

Lokesh

raj

unread,
Aug 31, 2011, 11:17:29 AM8/31/11
to Django users
Ya, I had to use the set_password method. And I used it by creating my
own save function in the UserForm class. Thanks for the help.
Reply all
Reply to author
Forward
0 new messages