root/trunk/pylucid_project/media/PyLucid/install_views.js

Revision 1498, 2.8 KB (checked in by JensDiemer, 2 years ago)

* Updates for ticket:163 - auth/login: password form with visibility:hidden
* Bugfixes for ticket:165 - _install: generate the SHA hash doesn't work with IE
* Merge some JS code together

Line 
1/* ___________________________________________________________________________
2 *  _install section login
3 *
4 * used in login and generate hash view!
5 *
6 * some routines exist from {{ PyLucid_media_url }}/shared_sha_tools.js
7 * and {{ PyLucid_media_url }}/sha.js
8 */
9
10/* uncomment to activate the debug window */
11//debug_msg = true;
12
13function shared_init() {
14    /* init stuff for both install views: install/generate hash */
15
16    /* The login form was hide via CSS. After JS loaded fine, we unhide it. */
17    unhide_by_id("password_form"); // from: shared_sha_tools.js
18
19    set_focus("plaintext_pass");
20}
21
22
23function login_init() {
24    shared_init();
25
26    /* After generating the install hash, the form should be submit */
27    submit_form = true;
28
29    debug("salt value from server:" + salt);
30    if (salt.length != SALT_LEN) {
31        alert("salt from Server fail!");
32        return false;
33    }
34    check_ok = true; // initial set to false in shared_sha_tools.js
35}
36
37
38function generate_hash_init() {
39    shared_init();
40
41    /* The form should not submit, after generating the install hash */
42    submit_form = false;
43
44    salt = generate_salt();
45    debug("generated JS salt value:" + salt);
46    if (salt==false) {
47        return false;
48    }
49    check_ok = true; // initial set to false in shared_sha_tools.js
50}
51
52
53function make_hash(submit) {
54    /*
55    processing the form data for the both install views: login & generate hash
56    The only difference here is:
57        * The given salt value:
58            * login view:
59                The salt value was insert into the html page from the server
60            * generate hash view:
61                The salt value is a random JS number generated in init()
62        * only the login view must submit the form.
63    */
64    if (check_ok != true) {
65       alert("Internal error. (check_ok not 'true')");
66       return false;
67    }
68
69    in_pass = get_plaintext_pass("plaintext_pass");
70    if (in_pass==false) {
71        return false;
72    }
73
74    sha = hex_sha1(salt + in_pass);
75    hash = "sha1$" + salt + "$" + sha;
76
77    set_value("hash", hash);
78    change_color("hash", "#90EE90");
79
80    set_value("plaintext_pass", "");
81    change_color("plaintext_pass", "#808080");
82
83    debug_confirm();
84    if (submit_form==true) {
85        /* Only in the login view, the form must be submit */
86        document.login.submit();
87    } else {
88        /* The generate hash should never send the form back to the server! */
89        return false;
90    }
91}
92
93
94function generate_salt() {
95    /* return a random string: six digit number */
96    salt = Math.random();
97    // convert to a string:
98    salt = "" + salt;
99    // get 5 decimal places after the comma:
100    salt = salt.substring(2, 7);
101    if (salt.length != SALT_LEN) {
102        alert("generating a random salt fail!");
103        return false;
104    }
105    return salt
106}
Note: See TracBrowser for help on using the browser.