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

问题描述 投票:0回答:1

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

在说“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()' {
javascript variables passwords key var
1个回答
0
投票

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())
© www.soinside.com 2019 - 2024. All rights reserved.