src/firefoxos/main.js

changeset 0
6a0957738c54
child 4
5d1908d87db8
equal deleted inserted replaced
-1:000000000000 0:ba46118cad40
1 /*
2 * OTPWCalc - One time password challenge response calculator client
3 * Copyright © 2013 Michael Schloh von Bennewitz <michael@schloh.com>
4 *
5 * OTPWCalc is free software: you can redistribute it and/or modify
6 * it under the terms of the European Union Public Licence, either
7 * version 1.1 of the license, or (at your option) any later version.
8 *
9 * OTPWCalc is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty
11 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the European Union Public License for more details.
13 *
14 * You should have received a copy of the European Union Public
15 * Licence along with OTPWCalc. If not, please refer to
16 * <http://joinup.ec.europa.eu/software/page/eupl/>.
17 *
18 * This file is part of project OTWPCalc, a one time password challenge
19 * response calculator client and is found at http://otpwcalc.europalab.com/
20 *
21 * main.js: ECMA JavaScript implementation
22 */
23
24 // <![CDATA[
25 //// This doesn't work with AJAX (use pageinit instead)
26 //// That means JavaScript in the head of any other HTML
27 //// will be ignored, only the data-role="page" is parsed
28 //$(document).ready(function() {
29 //$.mobile.ajaxLinksEnabled = false;
30 //});
31 $(document).on("mobileinit", function() {
32 $.extend( $.mobile , {
33 pageLoadErrorMessage: 'Either the page cannot be found or it cannot be loaded.'
34 });
35 });
36 //$(document).on("pageinit", function() {
37 //});
38
39 // the main logical entry point
40 function otpwcalc() {
41 var secr = $('#paswrd').val();
42 var user = $('#seedid').val();
43 var iter = parseInt($('#crement').val(), 10);
44 var hash = genotpmd5;
45 if ($('form input[name=radiohash]:checked').attr('id') == 'hashsha1')
46 hash = genotpsha1;
47 else if ($('form input[name=radiohash]:checked').attr('id') == 'hashr160')
48 hash = genotprmd160;
49 var form = arrtosix;
50 if ($('form input[name=radiodisplay]:checked').attr('id') == 'displayhex')
51 form = arrtohex;
52 var resp = hash(secr, user, iter);
53 //var resp = sjcl.random.randomWords(1,0);
54 return form(resp);
55 }
56
57 // helper function
58 function dosubmit() {
59 if ($('#seedid').val().length == 0) {
60 $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Seed ID');
61 return false;
62 }
63 else if ($('#crement').val().length == 0 || isNaN($('#crement').val())) {
64 $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Sequence #');
65 return false;
66 }
67 else {
68 $('#outext').css({'font-size': '0.9em', 'padding-top': '0.25em'}).text(otpwcalc());
69 $('#crement').val(parseInt($("#crement").val()) - $('#selectdecr').val());
70 return false;
71 }
72 }
73
74 // helper function
75 function doreset() {
76 $('#outext').css({'font-size': '1.125em', 'padding-top': '0'}).text('Please Click Submit For A OTP');
77 return true;
78 }
79 // ]]>

mercurial