foo290 / Django-Verify-Email

A two-step verification for new accounts by verifying email.
GNU General Public License v3.0
104 stars 33 forks source link

Problem in password after user gets verified. #72

Open Dhruvil2511 opened 1 year ago

Dhruvil2511 commented 1 year ago

User is successfully able to verify his email but in the password field i see this error : Invalid password format or unknown hashing algorithm. and thus i cant login. This is my view:

    form = RegistrationForm()
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            print(type(password))
            email = form.cleaned_data["email"]
            confirmPassword = form.cleaned_data["confirmpassword"]

            pattern = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b"

            if not re.match(r"^[a-zA-Z][a-zA-Z0-9._]{3,11}$", username):
                return render(
                    request,
                    "photos/register_form.html",
                    {
                        "error": "Username must start with a letter, should be 4 to 12 characters long, and can contain letters, numbers, periods, and underscores."
                    },
                )

            if re.fullmatch(pattern, email) == None:
                return render(
                    request,
                    "photos/register_form.html",
                    {"error": "Not a valid email address"},
                )

            if len(username) < 3:
                return render(
                    request,
                    "photos/register_form.html",
                    {"error": "Username must be at least 3 characters long"},
                )

            if len(password) < 8:
                return render(
                    request,
                    "photos/register_form.html",
                    {"error": "Password must be at least 8 characters long"},
                )

            if User.objects.filter(username=username).exists():
                return render(
                    request,
                    "photos/register_form.html",
                    {"error": "Username is already taken"},
                )
            if User.objects.filter(email=email).exists():
                return render(
                    request,
                    "photos/register_form.html",
                    {"error": "Email is already in use"},
                )

            if password == confirmPassword:
                # user = User.objects.create_user(username=username, email=email, password=password,user_bio='',pfp=None,is_verified=False,otp='')
                inactive_user= send_verification_email(request, form)  
                # user.save()   
                # if user is not None:
                #     user.backend = "django.contrib.auth.backends.ModelBackend"
                #     login(request, user)
                #     return redirect("gallery")

                # else:
                #     return render(
                #         request,
                #         "photos/register_form.html",
                #         {"error": "Something went wrong "},
                #     )
            else:
                return render(
                    request,
                    "photos/register_form.html",
                    {"error": "Password and confirm password doesn't match "},
                )

    return render(request, "photos/register_form.html",{"form": form})