コード例 #1
0
def register_view(request):
    if request.method == 'GET':
        return render(request, "register.html", {'method': 'GET'})
    else:
        graphs['r_counter'].inc()
        context = {'method': 'POST'}
        uname = request.POST.get('uname', None)
        pword = request.POST.get('pword', None)

        # KG: Uh... I'm not sure this makes sense.
        # Collect data to ensure good password use.
        # if pword not in graphs.keys():
        #     graphs[pword] = Counter(f'counter_{pword}', 'The total number of '\
        #       + f'times {pword} was used')
        # graphs[pword].inc()
        pword2 = request.POST.get('pword2', None)
        assert (None not in [uname, pword, pword2])
        if pword != pword2:
            context["success"] = False
            return render(request, "register.html", context)
        salt = extras.generate_salt(SALT_LEN)
        hashed_pword = extras.hash_pword(salt, pword)
        hashed_pword = salt.decode('utf-8') + '$' + hashed_pword
        u = User(username=uname, password=hashed_pword)
        u.save()
        return redirect("index.html")
コード例 #2
0
ファイル: views.py プロジェクト: bbhunter/insecure_website
def register_view(request):
    if request.method == 'GET':
        return render(request, "register.html", {'method': 'GET'})
    else:
        context = {'method': 'POST'}
        uname = request.POST.get('uname', None)
        pword = request.POST.get('pword', None)
        pword2 = request.POST.get('pword2', None)
        assert (None not in [uname, pword, pword2])
        if pword != pword2:
            context["success"] = False
            return render(request, "register.html", context)
        salt = extras.generate_salt(SALT_LEN)
        hashed_pword = extras.hash_pword(salt, pword)
        hashed_pword = salt.decode('utf-8') + '$' + hashed_pword
        u = User(username=uname, password=hashed_pword)
        u.save()
        return redirect("index.html")