From 422e476f496d944f0713484cbe0ee11b180cb12d Mon Sep 17 00:00:00 2001 From: ausiv4 Date: Sat, 25 Jul 2009 17:13:27 +0000 Subject: Moved register and login page to templates rather than cluttering views.py. Also added a 'key' function to the SRP javascript library, in case anyone wants to use K for encrypting communications. --- django/srpproject/srp/views.py | 84 ++----------------------------- django/srpproject/templates/login.html | 34 +++++++++++++ django/srpproject/templates/register.html | 42 ++++++++++++++++ javascript/srp.js | 17 +++++++ 4 files changed, 97 insertions(+), 80 deletions(-) create mode 100644 django/srpproject/templates/login.html create mode 100644 django/srpproject/templates/register.html diff --git a/django/srpproject/srp/views.py b/django/srpproject/srp/views.py index caa6076..1ad98dc 100644 --- a/django/srpproject/srp/views.py +++ b/django/srpproject/srp/views.py @@ -27,88 +27,12 @@ def generate_fake_salt(I): return salt, int(hashlib.sha256("%s:%s" % (salt, settings.SECRET_KEY)).hexdigest(), 16) def login_page(request): - return HttpResponse(""" - - - - - - - - - - -
- - - -
Username:
Password:
- -
- -""" % (request.get_host(), request.get_host(), request.get_host(),request.get_host(), request.get_host(), request.get_host())) + from django.shortcuts import render_to_response + return render_to_response('login.html',{'static_files': "http://%s/srp-test/javascript" % request.get_host()}) def register_page(request): - return HttpResponse(""" - - - - - - - - - - -
- - - - -
Username:
Password:
Confirm:
- -
- -""" % (request.get_host(), request.get_host(), request.get_host(),request.get_host(), request.get_host(), request.get_host())) + from django.shortcuts import render_to_response + return render_to_response('register.html',{'static_files': "http://%s/srp-test/javascript" % request.get_host()}) ### ### User Registration diff --git a/django/srpproject/templates/login.html b/django/srpproject/templates/login.html new file mode 100644 index 0000000..f949663 --- /dev/null +++ b/django/srpproject/templates/login.html @@ -0,0 +1,34 @@ + + + + + + + + + + + +
+ + + +
Username:
Password:
+ +
+ + diff --git a/django/srpproject/templates/register.html b/django/srpproject/templates/register.html new file mode 100644 index 0000000..82ce61e --- /dev/null +++ b/django/srpproject/templates/register.html @@ -0,0 +1,42 @@ + + + + + + + + + + + +
+ + + + +
Username:
Password:
Confirm:
+ +
+ + diff --git a/javascript/srp.js b/javascript/srp.js index a1bddff..0eff0ad 100644 --- a/javascript/srp.js +++ b/javascript/srp.js @@ -22,6 +22,7 @@ function SRP(username, password, ser, base_url) var url = base_url; var server = ser; var that = this; + var authenticated = false; function paths(str) { @@ -160,7 +161,10 @@ function SRP(username, password, ser, base_url) if(xhr.responseXML.getElementsByTagName("M").length > 0) { if(innerxml(xhr.responseXML.getElementsByTagName("M")[0]) == M2) + { that.success(); + authenticated = true; + } else that.error_message("Server key does not match"); } @@ -170,6 +174,19 @@ function SRP(username, password, ser, base_url) } } }; + this.key = function() + { + if(K == null) + if(authenticated) + { + K = SHA256(S); + return K; + } + else + that.error_message("User has not been authenticated."); + else + return K; + } this.success = function() { alert("Authentication successful."); -- cgit v1.2.3