Sorry, I guess I should've posted that as well :)

import string
class PasswordField(forms.CharField):

    # Setup the Field
    def __init__(self, *args, **kwargs):
        super(PasswordField, self).__init__(min_length = 7, required = True,
                        label = u'Password',
                        widget = forms.PasswordInput(render_value =
False),
                        *args, **kwargs)

    # Validate - 1+ Numbers, 1+ Letters
    def clean (self, value):

        # Setup Our List of Characters
        lower = list(string.lowercase[:26])
        upper = list(string.uppercase[:26])
        numbers = [str(i) for i in range(10)]

        # Assume False until Proven Otherwise
        numCheck = False
        charCheck = False

        # Loop until we Match
        for char in value:
            if not charCheck:
                if char in lower or char in upper:
                    charCheck = True
            if not numCheck:
                if char in numbers:
                    numCheck = True
            if numCheck and charCheck:
                break

        if not numCheck or not charCheck:
            raise forms.ValidationError(u'Your password must include at
least \
                                          one letter and at least one
number.')

On Thu, Sep 22, 2011 at 4:15 AM, Daniel Roseman <[email protected]>wrote:

>
>
> On Wednesday, 21 September 2011 23:42:02 UTC+1, Kurtis wrote:
>
>> Hey,
>>
>> I've created my own User Registration FormView. Everything seems to
>> work great except the password is always saved as "!". I can change
>> that with the "password changer" in the admin section of the site. I
>> am using an alternative authentication backend, so I'm not sure if
>> that was causing problems. I went ahead and included the default
>> authentication backend as well (at the front of the list) but that
>> didn't seem to change things. I've included my code at the bottom. Any
>> help would be greatly appreciated! Also, if there's anything wierd
>> about my code, let me know. I'm still learning.
>>
>> <snip>
>
>
>
>> class SignUpForm(forms.Form):
>>
>>     email = forms.EmailField(required = True, label = u'Email
>> Address')
>>     firstName = forms.CharField(required = True)
>>     lastName = forms.CharField(required = True)
>>     password = PasswordField()
>>     password_confirm = forms.CharField(label = u'Password
>> Confirmation',
>>                         widget = forms.PasswordInput(render_**value =
>> False),
>>                         required = True)
>>
>>     <snip>
>
>
> What is PasswordField?
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/UpH1hn6WWJwJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to