Subversion Repositories oidplus

Rev

Rev 149 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
149 daniel-mar 1
/*
2
 * OIDplus 2.0
3
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
 
18
min_password_length = 10; // see also setup/setup.js
19
 
20
function hexToBase64(str) {
21
        return btoa(String.fromCharCode.apply(null,
22
                    str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
23
}
24
 
25
function rehash_admin_pwd() {
150 daniel-mar 26
        var error = "";
27
 
28
        if (document.getElementById('admin_password').value.length == 0) {
29
                document.getElementById('config').innerHTML = "";
30
                return;
31
        }
32
 
149 daniel-mar 33
        if (document.getElementById('admin_password').value.length < min_password_length) {
150 daniel-mar 34
                error += 'Password too short. Need at least '+min_password_length+' characters<br>';
35
        }
36
 
37
        if (document.getElementById('admin_password').value != document.getElementById('admin_password2').value) {
38
                error += 'Passwords do not match.<br>';
39
        }
40
 
41
        if (error != "") {
42
                document.getElementById('config').innerHTML = error;
149 daniel-mar 43
        } else {
44
                document.getElementById('config').innerHTML = '<b>define</b>(\'OIDPLUS_ADMIN_PASSWORD\',   \'' + hexToBase64(sha3_512(document.getElementById('admin_password').value)) + '\'); // base64 encoded SHA3-512 hash<br>';
45
        }
46
}