Posted by & filed under Uncategorized.

During the preparations for the Enigma election, an student society for the students located at the department of technology at HiØ. I took part of making the election system handing voters and the votes.

To start off, we have a database containing all the members and their user name. Since the usernames are generated by the school, it enables us to combine them with @hiof.no to complete a personal email address. So to verify our votes they will need to submit their username. Based on this username we can genarate a personal key witch we can email to the user. We can now be sure that only the user sees this key and be able to use it.

The frontpage (index.php) hadles the user verification and email the the key. When the user opens the email, the hash key is passed with in the link. When clicking the link you get back to the frontpage and your key is stored within a session before you are relocated to vote.html.

if(isset($_REQUEST['key'])) {
    $key = $_REQUEST['key'];
    $_SESSION['mykey'] = $key;
    header("Location: vote.html");
}

The image illustrates the different elections with tabs and lists the candidates. When the vote is placed the next button is enabled and you can proceed.

vote example

Vote.html is html page with general html and some awesome jQuery. Tho the code presented it self might not be awesome, but jQuery sure is! All the stuff thats happening now is pure ajax calls to feedHandler.php. This php file handles the request from ajax and vote.html, some of the requests is just initiated with setting a variable true and some require some numbers and stuff. Down bellow is some of the handlers presented with code.

$type = $_REQUEST['getCandidatesByElection'];

if(isset($type)) {
    echo json_encode(getCandidatesByElection($type));
}
if(isset($election) && isset($candidate)) {
    setVote($election, $candidate);
}
if(isset($submitVote)) {
    submitVotes();
}

To wrap it up, I use these handlers to save data and submit them afterwards. What I think is the awesome part is that I can store information with sessions. So when setVote is called, we are saving the results from that election to a session variable. When completed the results is submited to the database with submitVotes. Tho it might be smart to mention that the vote results is updated by the private key. The key entry is made when you submit your user name at the frontpage and it reserves a slot for your votes.

A demo is located here: http://www.it-stud.hiof.no/~olavjh/prosjekter/enigma_valg/?key=286d1a46628c32c7708489f68e531fc5

Leave a Reply

  • (will not be published)