| 1 | /* ___________________________________________________________________________ |
|---|
| 2 | * Some needed stuff round the SHA-JS-Login |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | check_ok = false; |
|---|
| 6 | debug_msg = false; |
|---|
| 7 | |
|---|
| 8 | // length of a SHA1 hexdigest string: |
|---|
| 9 | HASH_LEN = 40; |
|---|
| 10 | // length of the salt and challenge value string: |
|---|
| 11 | SALT_LEN = 5; |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | if (!document.getElementById) { |
|---|
| 15 | alert("Error: Your Browser is not supported!"); |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | if (navigator.cookieEnabled) { |
|---|
| 19 | if (navigator.cookieEnabled != true) { |
|---|
| 20 | alert("You must enable Cookies in your Browser!"); |
|---|
| 21 | } |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | /* ___________________________________________________________________________ |
|---|
| 25 | * needfull generic functions: |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | function get_value(object_id) { |
|---|
| 29 | // get a form value |
|---|
| 30 | try { |
|---|
| 31 | return document.getElementById(object_id).value; |
|---|
| 32 | } catch (e) { |
|---|
| 33 | alert("get_value('"+object_id+"') error! " + e); |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | function set_value(object_id, value) { |
|---|
| 38 | // set a form value |
|---|
| 39 | try { |
|---|
| 40 | obj = document.getElementById(object_id).value = value; |
|---|
| 41 | } catch (e) { |
|---|
| 42 | alert("set_value('"+object_id+"', '"+value+"') error! " + e); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | function set_focus(object_id) { |
|---|
| 47 | try { |
|---|
| 48 | debug("set focus on id:" + object_id); |
|---|
| 49 | document.getElementById(object_id).focus(); |
|---|
| 50 | } catch (e) { |
|---|
| 51 | alert("set_focus('"+object_id+"') error:" + e); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | function hide_by_id(object_id) { |
|---|
| 56 | try { |
|---|
| 57 | debug("hide_by_id: "+object_id); |
|---|
| 58 | obj = document.getElementById(object_id); |
|---|
| 59 | obj.style.display = 'none'; |
|---|
| 60 | } catch (e) { |
|---|
| 61 | alert("hide_by_id('"+object_id+"') error:" + e); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | function unhide_by_id(object_id) { |
|---|
| 65 | try { |
|---|
| 66 | debug("unhide_by_id: "+object_id); |
|---|
| 67 | obj = document.getElementById(object_id); |
|---|
| 68 | obj.style.display = 'block'; |
|---|
| 69 | } catch (e) { |
|---|
| 70 | alert("unhide_by_id('"+object_id+"') error:" + e); |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | function change_color(object_id, color_name) { |
|---|
| 75 | try { |
|---|
| 76 | debug("change_color: "+object_id); |
|---|
| 77 | obj = document.getElementById(object_id); |
|---|
| 78 | obj.style.backgroundColor = color_name; |
|---|
| 79 | } catch (e) { |
|---|
| 80 | alert("change_color('"+object_id+"', '"+color_name+"') error:" + e); |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /* ___________________________________________________________________________ |
|---|
| 85 | * special functions: |
|---|
| 86 | */ |
|---|
| 87 | |
|---|
| 88 | function check_ascii_only(data) { |
|---|
| 89 | for (var i = 1; i <= data.length; i++) { |
|---|
| 90 | unicode_charcode = data.charCodeAt(i); |
|---|
| 91 | if (unicode_charcode > 127) { |
|---|
| 92 | alert("Only ASCII letters are allowed!"); |
|---|
| 93 | return false; |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | return true; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | function get_plaintext_pass(object_id) { |
|---|
| 100 | try { |
|---|
| 101 | in_pass = get_value(object_id); |
|---|
| 102 | debug("in_pass:" + in_pass); |
|---|
| 103 | if (in_pass.length<8) { |
|---|
| 104 | alert("Password min len 8! - current len:" + in_pass.length); |
|---|
| 105 | set_focus(object_id) |
|---|
| 106 | return false; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | if (check_ascii_only(in_pass) == false) { |
|---|
| 110 | set_focus(object_id) |
|---|
| 111 | return false; |
|---|
| 112 | } |
|---|
| 113 | return in_pass; |
|---|
| 114 | } catch (e) { |
|---|
| 115 | alert("get_plaintext_pass() error:" + e); |
|---|
| 116 | return false; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | function make_SHA(txt) { |
|---|
| 121 | try { |
|---|
| 122 | debug("make_SHA(" + txt + "):"); |
|---|
| 123 | SHA_hexdigest = hex_sha1(txt); // from: sha.js |
|---|
| 124 | len = SHA_hexdigest.length; |
|---|
| 125 | if (len != HASH_LEN) { |
|---|
| 126 | alert("make_SHA() error! wrong length:" + len); |
|---|
| 127 | return false; |
|---|
| 128 | } |
|---|
| 129 | debug(SHA_hexdigest); |
|---|
| 130 | return SHA_hexdigest; |
|---|
| 131 | } catch (e) { |
|---|
| 132 | alert("make_SHA() error:" + e); |
|---|
| 133 | return false; |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | /* ___________________________________________________________________________ |
|---|
| 139 | * debugging: |
|---|
| 140 | */ |
|---|
| 141 | |
|---|
| 142 | function init_debug() { |
|---|
| 143 | /* Create a debug window, if it's not exists */ |
|---|
| 144 | try { |
|---|
| 145 | if (debug_msg != true) { return; } |
|---|
| 146 | try { |
|---|
| 147 | if (debug_window) { |
|---|
| 148 | return; |
|---|
| 149 | } |
|---|
| 150 | } catch (e) {} |
|---|
| 151 | debug_window = window.open("", "Debug", "dependent=yes, resizable=yes, scrollbars=yes, width=350, height=400, top=1, left=" + window.outerWidth); |
|---|
| 152 | |
|---|
| 153 | debug_win = debug_window.document; |
|---|
| 154 | debug_win.writeln("<style>* { font-size: 0.85em; }</style>"); |
|---|
| 155 | |
|---|
| 156 | var now = new Date(); |
|---|
| 157 | now = now.toLocaleString(); |
|---|
| 158 | |
|---|
| 159 | debug_win.writeln("<h1>JS Debug - "+now+":</h1>"); |
|---|
| 160 | debug_win.writeln("---[DEBUG START]---"); |
|---|
| 161 | debug_win.writeln("cookie:" + document.cookie +"<br />"); |
|---|
| 162 | } catch (e) { |
|---|
| 163 | alert("init_debug() error:" + e); |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | function debug(msg) { |
|---|
| 169 | try { |
|---|
| 170 | if (debug_msg != true) { return; } |
|---|
| 171 | init_debug(); |
|---|
| 172 | debug_win.writeln(msg + "<br />"); |
|---|
| 173 | debug_window.focus(); |
|---|
| 174 | // scroll to the last lines |
|---|
| 175 | debug_window.scrollBy(0, 1000); |
|---|
| 176 | } catch (e) { |
|---|
| 177 | alert("debug('"+msg+"') error:" + e); |
|---|
| 178 | } |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | function debug_confirm() { |
|---|
| 183 | try { |
|---|
| 184 | if (debug_msg != true) { return; } |
|---|
| 185 | debug_window.focus(); |
|---|
| 186 | debug_win.writeln("---[DEBUG END]---"); |
|---|
| 187 | alert("OK for closing the debug window."); |
|---|
| 188 | debug_window.close(); |
|---|
| 189 | debug_window = false; |
|---|
| 190 | } catch (e) { |
|---|
| 191 | alert("debug_confirm() error:" + e); |
|---|
| 192 | } |
|---|
| 193 | } |
|---|