
Partial Class login_ChangePW
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs)
        Dim url = Request.ServerVariables("URL")
        Session.Add("urltochangepw", url)
        If VERAG_PROG_ALLGEMEIN.cCryptography.Decrypt(Session.Item("TokenforEmail").ToString()) = VERAG_PROG_ALLGEMEIN.cCryptography.Decrypt(Request.QueryString("Par1")) AndAlso VERAG_PROG_ALLGEMEIN.cCryptography.Decrypt(Session.Item("TokenforEmail").ToString()) = Not Nothing AndAlso VERAG_PROG_ALLGEMEIN.cCryptography.Decrypt(Request.QueryString("Par1")) = Not Nothing Then
            If getDateoftoken(VERAG_PROG_ALLGEMEIN.cCryptography.Decrypt(Request.QueryString("Par1"))) = True Then
                txt_Pw_WH.Enabled = False
                regexval_txt_Pw_WH.Enabled = False
                If IsPostBack Then
                    reqPasswtxt.Validate()
                    reqPassw1txt.Validate()
                End If
            Else
                btn_submitpw.Enabled = False

            End If
        Else
            MsgBox("Link ist abgelaufen. Bitte neue E-Mail senden.", MsgBoxStyle.Critical, "Error06")
            Response.Redirect("ForgotPW.aspx")
        End If
    End Sub

    Protected Sub txt_Pw_WH_TextChanged(sender As Object, e As EventArgs)
        regexval_txt_Pw_WH.Validate()
        confirmPasswordReq.Validate()
        If confirmPasswordReq.IsValid Then
            btn_submitpw.Enabled = True
        Else
            btn_submitpw.Enabled = False
        End If
    End Sub
    Public Function geturlofpage() As String
        Dim url = Request.Url.Authority + HttpContext.Current.Request.RawUrl.ToString()

        If Request.ServerVariables("HTTPS") = "on" Then
            url = "https://" + url
        Else
            url = "http://" + url
        End If
        Return url
    End Function

    Protected Sub btn_submitpw_Click(sender As Object, e As EventArgs)
        Dim tempstr As String = ""
        Dim Msg, Style, Title As String
        reqPasswtxt.Validate()
        reqPassw1txt.Validate()
        If confirmPasswordReq.IsValid = True Then
            tempstr = txt_Pw.Text
        Else
            tempstr = "Error01"
        End If
        If txt_Pw.Text = tempstr Then
            Msg = "PW erfolgreich geändert!"
            Style = vbOKOnly + vbInformation + vbDefaultButton1
            Title = "Information"
            MsgBox(Msg, Style, Title)

            If MsgBox(Msg, Style, Title).Ok Then
                Response.Redirect("login_FLEX.aspx")
            End If
        ElseIf tempstr = "Error01" Then
            Msg = "PW nicht erfolgreich geändert!"
            Style = vbAbortRetryIgnore + vbCritical + vbDefaultButton1
            Title = "Error"
            MsgBox(Msg, Style, Title)
            If MsgBox(Msg, Style, Title).Retry Then
                Response.Redirect(Request.RawUrl)
            ElseIf MsgBox(Msg, Style, Title).Abort Then
                Response.Redirect("../newPageJulius_Sidebar.aspx")
            ElseIf MsgBox(Msg, Style, Title).Ignore Then
                Try

                Catch ex As Exception

                End Try
            End If
        End If
    End Sub

    Protected Sub txt_Pw_TextChanged(sender As Object, e As EventArgs)
        regexval_txt_Pw.Validate()
        If regexval_txt_Pw.IsValid Then
            txt_Pw_WH.ReadOnly = False
            regexval_txt_Pw_WH.Enabled = True
        Else
            txt_Pw_WH.ReadOnly = True
            regexval_txt_Pw_WH.Enabled = False
        End If
    End Sub

    Function getDateoftoken(tokenname As String) As Boolean
        Dim data() As Byte = Convert.FromBase64String(tokenname)
        Dim wenn As DateTime = DateTime.FromBinary(BitConverter.ToInt64(data, 0))

        If wenn < DateTime.UtcNow.AddMinutes(-30) Then
            Return False
            tokenname = ""
            MsgBox("Token nicht gefunden oder zu alt!" + Environment.NewLine + "Bitte erneut Mail senden!")
        Else

            Return True
        End If
    End Function

End Class
