2016-11-24 56 views
-1

我们有一个要求,如果用户忘记了他们的密码,他们应该要求并通过电子邮件接收忘记密码链接重置他们的密码。为什么我的日期比较不起作用?

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

只要他们收到一封电子邮件链接重置密码,并且用户点击链接重置密码,用户将看到一个屏幕重置密码。迄今为止,这工作非常顺利。

我遇到的问题是,当用户点击电子邮件链接重置密码超过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> 

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

+0

一个空白的屏幕是不是非常有帮助做Equal or =

这样

If DateOfCreation = DateTime.Now then msgbox "Reset" else msgbox "Expired" End if 

。总是有更多的信息。在IIS日志记录中,使用F12工具进行交互式调试。采取第一步来解决你的问题,并看看'空白屏幕'的结果 –

+0

@Tairoc:如果你添加了一个.aspx的代码片段来显示你的面板的标记,以及它们的父控件(如果有的话),这可能会有所帮助。另外,通过“空白页面”,你的意思是一个没有任何*内容的白屏,或者你的意思是过期消息是不可见的? –

+4

'dtNow> dtExp'永远不会是真的基于您的代码 –

回答

1

如果仍然超过24小时的情况,然后根据你的代码

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 
+0

对不起ro不同意你,但使用<>表达式不起作用。 dtNow大于(>)比dtExpt或dtNow小于(<)。 – Tairoc

+0

尝试使用'grether than'只''' –

+0

请参阅更新的答案 –

相关问题