当前位置: 代码迷 >> JavaScript >> 如何使功能输出密码功能的键
  详细解决方案

如何使功能输出密码功能的键

热度:91   发布时间:2023-06-13 12:43:02.0

我正在尝试创建一个页面,使用某个日期以来的天数作为密码。 唯一有效的密码是静态的,并且用“”括起来。 我希望能够将自几天以来的结果用作密码。 我该怎么做呢?

在显示“ if (pass1 == "abcde") {的行中,我if (pass1 == "abcde") {尝试将“ abcde ”更改为函数的名称,以及从该函数获得的最终变量。

function passWord() {
    var testV = 1;
    var pass1 = prompt('Please Enter Your Password to see deez burgerz','Password ');

    while (testV < 3) {
        if (!pass1) 
            history.go(-1);
        if (pass1 == "abcde") {
            alert('Lucky guess...');
            window.open('http://bowenpowell.com');
            break;
        } 
        testV+=1;
        var pass1 = 
            prompt('Access Denied - Password Incorrect, ur dumb.','Password');
    }
    if (pass1.toLowerCase()!="password" & testV ==3) 
        history.go(-1);
    return " ";
} 

自几天以来我的功能:

function dateFunction() {
    var currentDate = new Date(),
      m = currentDate.getMonth() +1,
      d = currentDate.getDate(),
      y = currentDate.getFullYear();
    var current = y + "/" + m + "/" + d;
    var date2 = '2018/9/4';
current = current.split('/');
date2 = date2.split('/');
current = new Date(current[0], current[1], current[2]);
date2 = new Date(date2[0], date2[1], date2[2]);
current_unixtime = parseInt(current.getTime() / 1000);
date2_unixtime = parseInt(date2.getTime() / 1000);
var timeDifference = current_unixtime - date2_unixtime;
var timeDifferenceInHours = timeDifference / 60 / 60;
var timeDifferenceInDays = timeDifferenceInHours  / 24 + 2;


    document.getElementById("demo").innerHTML = timeDifferenceInDays;
}

我试过了

if (pass1 == timeDifferenceInDays) {
if (pass1 == dateFunction()) {
if pass1 == timeDifferenceInDays {
if pass1 == dateFunction() {
if pass1 == 'timeDifferenceInDays' {
if pass1 == 'dateFunction()' {

dateDifference()需要返回要用作密码的值。

 function dateFunction() { var currentDate = new Date(), m = currentDate.getMonth() + 1, d = currentDate.getDate(), y = currentDate.getFullYear(); var current = y + "/" + m + "/" + d; var date2 = '2018/9/4'; current = current.split('/'); date2 = date2.split('/'); current = new Date(current[0], current[1], current[2]); date2 = new Date(date2[0], date2[1], date2[2]); current_unixtime = parseInt(current.getTime() / 1000); date2_unixtime = parseInt(date2.getTime() / 1000); var timeDifference = current_unixtime - date2_unixtime; var timeDifferenceInHours = timeDifference / 60 / 60; var timeDifferenceInDays = timeDifferenceInHours / 24 + 2; document.getElementById("demo").innerHTML = timeDifferenceInDays; return timeDifferenceInDays.toString(); } 

然后,您可以使用:

if (pass1 == dateFunction())
  相关解决方案