Public Class frmChangePWD

    Public PERSONAL As VERAG_PROG_ALLGEMEIN.cMitarbeiter = Nothing

    Sub New(PERSONAL As VERAG_PROG_ALLGEMEIN.cMitarbeiter)
        InitializeComponent()
        Me.PERSONAL = PERSONAL
        If PERSONAL.mit_PasswortChanged Is Nothing Then
            Label4.Visible = True
        End If
    End Sub

    Private Sub btnSpeichern_Click(sender As Object, e As EventArgs) Handles btnSpeichern.Click
        If PERSONAL Is Nothing Then
            MsgBox("Altes Passwort falsch!")
            Exit Sub
            Me.Close()
        End If

        Me.DialogResult = Windows.Forms.DialogResult.None
        If PERSONAL.mit_pwd <> txtPwdOld.Text Then
            MsgBox("Altes Passwort falsch!")
            Exit Sub
        End If

        If txtPwdNew1.Text <> "" Then
            If txtPwdNew1.Text = txtPwdNew2.Text Then

                If txtPwdNew1.Text = PERSONAL.mit_pwd Then
                    MsgBox("Das neue Passwort muss sich vom alten unterscheiden!")
                    Exit Sub
                End If

                If txtPwdNew1.Text.Length <= 3 Then
                    MsgBox("Das Passwort muss mehr als 3 Zeichen haben!")
                    Exit Sub
                End If

                Dim bool_zahl = False
                Dim bool_text = False
                For Each s In txtPwdNew1.Text
                    If IsNumeric(s) Then
                        bool_zahl = True
                    Else
                        bool_text = True
                    End If
                Next
                If Not bool_zahl Or Not bool_text Then
                    MsgBox("Das Passwort muss Zahlen und Buchstaben enthalten!")
                    Exit Sub
                End If

                Dim sql As New VERAG_PROG_ALLGEMEIN.SQL
                If sql.doSQL("UPDATE tblMitarbeiter SET mit_pwd='" & txtPwdNew1.Text & "', mit_PasswortChanged=GETDATE() WHERE mit_id = '" & PERSONAL.mit_id & "'", "ADMIN") Then
                    VERAG_PROG_ALLGEMEIN.cAllgemein.LOAD_DATA() 'Neu laden
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                End If
            Else
                MsgBox("Neue Passwörter stimmen nicht überein!")
                Exit Sub
            End If
        End If
    End Sub

    Private Sub txtPwdNew2_TextChanged(sender As Object, e As EventArgs) Handles txtPwdNew2.TextChanged

    End Sub

    Private Sub txtPwdNew2_KeyDown(sender As Object, e As KeyEventArgs) Handles txtPwdNew2.KeyDown
        If e.KeyCode = Keys.Return Then
            btnSpeichern.PerformClick()
        End If
    End Sub
End Class