【问题标题】:How to make function output the key for a password function如何使函数输出密码函数的密钥
【发布时间】:2019-07-09 01:17:56
【问题描述】:

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

在写有“if (pass1 == "abcde") {”的行上,我尝试将“abcde”更改为我的函数的名称 daysSince 以及我从该函数获得的最终 var。

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()' {

【问题讨论】:

  • 首先,您在最终的if 声明中缺少&amp;,应该是&amp;&amp;
  • 显示您尝试过但不起作用的代码,以便我们告诉您您做错了什么。
  • 当您将"abcde" 替换为函数名称时,您是否将() 放在函数名称之后?您需要这样做才能调用该函数。
  • @Barmar 我已经用我尝试过的方法更新了代码
  • dateFunction() 不返回任何内容。

标签: javascript variables passwords key var


【解决方案1】:

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())

【讨论】:

    猜你喜欢
    • 2014-05-11
    • 2021-03-15
    • 2017-03-29
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    相关资源
    最近更新 更多