检查输入的密码是否匹配

时间:2019-01-24 00:27:41

标签: javascript jquery asp.net-ajax

我想创建一个函数,其中用户输入密码,并且必须与此密码(Sub ReportPivot () ' ' ReportPivot Macro ' ' Deactivate ScreenUpdating Application.ScreenUpdating = False ' Declare Variables Dim DataSheet As Worksheet Dim LastRow As Long Dim LastCol As Long Dim DataRange As Range Dim PSheet As Worksheet Dim PCache As PivotCache Dim PTable As PivotTable Dim PField As PivotField ' Name Data Sheet ActiveSheet.Name = "Data" ' Define DataSheet Set DataSheet = Worksheets("Data") ' Define DataRange Set DataRange = DataSheet.Cells(1, 1).CurrentRegion ' Add the Processed Report sheet Set PSheet = ActiveWorkbook.Worksheets.Add PSheet.Name = "Processed Report" ' Insert DataPivotTable Set PTable = PSheet.PivotTableWizard(SourceType:=xlDatabase, _ SourceData:=DataRange, _ TableDestination:=PSheet.Cells(2, 2), _ TableName:="DataPivotTable", _ RowGrand:=False, _ ColumnGrand:=False) ' Set to Tabular Layout PTable.RowAxisLayout xlTabularRow ' Insert Row Fields Dim RowFields As Variant RowFields = Array("productid", "Start Date", "End Date", "OriginalBlock", "ReleaseDays", "ReleaseDate") Dim field For Each field In RowFields Set PField = PTable.pivotFields(field) With PField .Orientation = x1RowField .position = Application.Match(field, RowFields, False) .Subtotals(place) = False End With Next field ' Ungroup Date Fields Dim DateFields As Variant DateFields = Array("Start Date", "End Date", "ReleaseDate") Dim dfield For Each dfield In DateFields Set PField = PTable.pivotFields(dfield) PField.DataRange.Cells(1).Ungroup Next dfield ' Sort oldest to newest PTable.pivotFields("Start Date").AutoSort _ xlAscending, "Start Date" ' Resize columns Cells.EntireColumn.AutoFit ' Deactivate repeat labels PTable.RepeatAllLabels xlDoNotRepeatLabels ' Reactivate ScreenUpdating Application.ScreenUpdating = True end sub )匹配。当用户单击productid,OriginalBlock,ReleaseDays,ReleaseDate,Start Date,End Date JRS,16,6,,5/1/2019,5/31/2019 JRS,16,6,,5/1/2020,5/31/2020 JRS,16,8,,6/26/2020,6/27/2020 JRS,16,15,,6/28/2020,7/25/2020 JRS,1,22,,7/26/2020,8/25/2020 MAS,11,6,,5/1/2019,5/31/2019 MAS,11,8,,6/1/2019,6/27/2019 MAS,11,15,,6/28/2019,7/25/2019 MAS,1,22,,7/26/2019,8/25/2019 MAS,11,15,,8/26/2019,9/8/2019 MAS,11,8,,9/9/2019,9/30/2019 MAS,11,6,,10/1/2019,10/5/2019 MAS,11,6,,5/1/2020,5/31/2020 MAS,1,22,,7/26/2020,8/25/2020 SUP,25,6,,5/1/2019,5/31/2019 SUP,25,8,,6/1/2019,6/27/2019 SUP,25,15,,6/28/2019,7/25/2019 SUP,1,22,,7/26/2019,8/25/2019 SUP,25,15,,8/26/2019,9/8/2019 SUP,25,8,,9/9/2019,9/30/2019 SUP,25,6,,10/1/2019,10/5/2019 SUP,25,6,,5/1/2020,5/31/2020 SUP,25,8,,6/1/2020,6/24/2020 SUP,25,15,,6/25/2020,7/25/2020 SUP,1,22,,7/26/2020,8/25/2020 SUP,25,15,,8/26/2020,9/8/2020 SUP,25,8,,9/9/2020,9/30/2020 SUP,25,6,,10/1/2020,10/6/2020 时,它将检查键入的密码是否与pwd1209!匹配。

submit button

1 个答案:

答案 0 :(得分:1)

您的JS代码不完整,此外,问题的关键在于密码是字符串,因此密码必须在引号内。为确保您的解决方案不安全,因为可以看到JS,因此任何人都可以找到密码,您应该尝试使用后端解决方案来进行密码检查。

$(document).ready(function() {
  $('#submit').click(function() {
    if ($('#pwd').val() === '') {
      alert('Add the password.');
    } else if ($('#pwd').val() !== 'pwd1209!') {
      alert('Incorrect password.');
    } else {
      alert('Correct password');
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="password" id="pwd" class="form" placeholder="type your password">
<button class="btn" id="submit"> Submit</button>