package jregistrate;
import java.lang.System;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.sql.*;
import org.sqlite.JDBC;
/* Copyright (C) 2015 Blindspot Security LLC. All rights reserved.
* Author: Timothy D. Morgan
*/
public final class register extends BaseServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("");
writer.println("
");
writer.println("Register for an Account");
writer.println("");
writer.println("");
String error = (String)request.getAttribute("error");
if (error != null)
{
writer.println("ERROR:"+error+"");
}
writer.println("");
String member_id = request.getParameter("member_id");
member_id = (member_id == null) ? "" : member_id;
String last_four = request.getParameter("last_four");
last_four = (last_four == null) ? "" : last_four;
//String zip_code = request.getParameter("zip_code");
//zip_code = (zip_code == null) ? "" : zip_code;
String username = request.getParameter("username");
username = (username == null) ? "" : username;
String password = request.getParameter("password");
password = (password == null || !password.equals(request.getParameter("conf_pwd"))) ? "" : password;
writer.println("");
writer.println("");
writer.println("");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
request.setAttribute("error", null);
try
{
String member_id = request.getParameter("member_id");
member_id = (member_id == null) ? "" : member_id;
String last_four = request.getParameter("last_four");
last_four = (last_four == null) ? "" : last_four;
//String zip_code = request.getParameter("zip_code");
//zip_code = (zip_code == null) ? "" : zip_code;
String username = request.getParameter("username");
username = (username == null) ? "" : username;
String password = request.getParameter("password");
password = (password == null || !password.equals(request.getParameter("conf_pwd"))) ? "" : password;
Connection db = openDB();
PreparedStatement ps = db.prepareStatement("SELECT * FROM members WHERE member_id=?");
ps.setString(1, member_id);
ResultSet rs = ps.executeQuery();
long start = System.nanoTime();
PrintWriter writer = response.getWriter();
if (rs.next())
{
if (last_four.equals(decryptLastFour(rs.getString("enc_last_four"))))
{
if (!"".equals(password))
{
// member_id already registered?
// username already registered?
response.setContentType("text/html");
writer.println("Registration Successful!");
return;
}
else
request.setAttribute("error", "Bad password or passwords don't match");
}
}
response.addHeader("X-Response-Time", String.format("%fms", (System.nanoTime()-start)/1000000.0));
if (request.getAttribute("error") == null)
request.setAttribute("error", "Invalid personal information specified. Try again.");
}
catch (Exception e)
{
request.setAttribute("error", "Unknown error occurred. See logs.");
e.printStackTrace();
}
doGet(request, response);
}
}