-1
我正在一個項目,我有一個用戶輸入用戶名電子郵件和密碼的窗體。我想散列密碼並保存。我注意到當我通過管理頁面創建用戶時,它會自動創建密碼並在保存之前對其進行哈希處理。我想做同樣的事情。有沒有什麼辦法,我這樣做...不能弄清楚如何哈希passowrd django
這就是我現在所擁有的對視......
def signup(request):
# the following will determine if the form is submitted or not
if request.method == 'POST':
form = SignupForm(request.POST)
# the following section validates the entire form and processed the data
if form.is_valid():
# the following will make sure the data is clean and then store them
# into new variables
cd = form.cleaned_data
username = cd['username']
password = cd['password']
verify = cd['verify']
email = cd['email']
# the folloiwng will make sure the password and verification are matching
# before storing the info into the database
if password == verify:
new_user = User.objects.create(
username = username,
password = password,
email = email,
)
# the following will store the username of the account that was just
# created in to the session so that the app can track the user that
# is logged in
request.session['username'] = username
return redirect('profile_setup')
else:
# if password and verification dont match, a message will be sent
# back to the user so they can fill in the correct info.
message = 'Password and Verify dont match'
parameters = {
'form':form,
'message':message,
}
return render(request, 'tabs/signup.html', parameters)
else:
# this will display the form if it waas not submmited.
form = SignupForm()
message = 'Fill out the form'
parameters = {
'form':form,
'message':message,
}
return render(request, 'tabs/signup.html', parameters)