为什么我的日期比较不起作用?

时间:2016-11-24 03:27:29

标签: asp.net vb.net

我们要求如果用户忘记了密码,他们应该通过电子邮件请求并接收忘记密码链接以重置密码。

我使用日期时间比较以及唯一代码形式的令牌来确保一定程度的安全性。

只要他们收到重置密码的电子邮件链接,并且用户点击重置密码的链接,就会向用户显示重置密码的屏幕。到目前为止,这种方法很有效。

我遇到的问题是当用户点击电子邮件链接重置密码超过24小时后发送链接的电子邮件时,他们会得到一个空白页。

我们希望用户获得一个页面,上面显示重置密码链接已过期。这只是一次使用,但该消息不可见。

我做错了什么?

以下是我正在使用的代码:

If dr.HasRows Then
    Dim dtCreate As DateTime = DateTime.Now
    Dim dtNow As DateTime = DateTime.Now
    Dim dtExp As DateTime = dtCreate.AddDays(1)
    If dtNow > dtExp Then
        ResetPwdPanel.Visible = False
        Expired.Visible = True
    Else
        ResetPwdPanel.Visible = True
        Expired.Visible = False
        lblExpired.Text = "Reset password link has expired. It was for one time use only"
        Return

    End If
End If

'标记:

<form id="form1" runat="server">

<div>

<asp:Panel ID="ResetPwdPanel" runat="server" Visible="false" >

<fieldset style="width:400px">

<legend>Reset Password</legend>    

<table>

<tr>

<td>New password: </td><td>
    <div class="input text"> 
    <asp:TextBox ID="txtNewPwd" style="width:150px;" TextMode="Password" runat="server"></asp:TextBox></div><br />

    <asp:RequiredFieldValidator ID="rfvNewPwd" runat="server" 

        ControlToValidate="txtNewPwd" Display="Dynamic" 

        ErrorMessage="Please enter new password" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>

    </td>

</tr>

<tr>

<td>Confirm Passsword: </td><td>
<div class="input text"> 
    <asp:TextBox ID="txtConfirmPwd" style="width:150px;" TextMode="Password" runat="server"></asp:TextBox></div><br />

    <asp:RequiredFieldValidator ID="rfvConfirmPwd" runat="server" 

        ControlToValidate="txtConfirmPwd" Display="Dynamic" 

        ErrorMessage="Please re-enter password to confirm" ForeColor="Red" 

        SetFocusOnError="True"></asp:RequiredFieldValidator>

    <asp:CompareValidator ID="cmvConfirmPwd" runat="server" 

        ControlToCompare="txtNewPwd" ControlToValidate="txtConfirmPwd" 

        Display="Dynamic" ErrorMessage="Password didn't match" ForeColor="Red" 

        SetFocusOnError="True"></asp:CompareValidator>

    </td>

</tr>

<tr>

<td>

    &nbsp;</td><td>

    <asp:Button ID="btnChangePwd" runat="server" Text="Change Password" 

            onclick="btnChangePwd_Click" /></td>

</tr>

    <tr>

        <td colspan="2">

            <asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>

        </td>

    </tr>

</table>

</fieldset>        

</asp:Panel>

 <asp:panel ID="Expired" runat="server">
   <asp:Label ID="lblExpired" runat="server" Text="" style="color: #FF0000"></asp:Label></asp:panel>

     我们有两个面板控件。一个显示重置密码控件(这个工作),而另一个显示重置密码链接到期消息(这不起作用)。

1 个答案:

答案 0 :(得分:1)

如果情景仍超过24小时,则执行Equal or =

像这样

If DateOfCreation = DateTime.Now then

    msgbox "Reset"
else
        msgbox "Expired"
End if

基于您的代码

If dr.HasRows Then
                Dim dtCreate As DateTime = DateTime.Now
                Dim dtNow As DateTime = DateTime.Now

                If dtCreate = dtNow Then


 ResetPwdPanel.Visible = True
                    Expired.Visible = False
                    Return
                Else
                      ResetPwdPanel.Visible = False
                    Expired.Visible = True

                End If
            End If
相关问题