-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordReset.vb
74 lines (64 loc) · 3.42 KB
/
PasswordReset.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Imports System.ComponentModel
Imports System.Data.SqlClient
Public Class PasswordReset
Private ReadOnly _studentID As String
Public Sub New(StudentID As String)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
_studentID = StudentID
End Sub
Private Sub PasswordReset_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub DOB_Validate(sender As Object, e As CancelEventArgs) Handles DOBPicker.Validating
If DOBPicker.Value.Date >= Today Then
MessageBox.Show("Enter a Valid Date.")
ElseIf (Today.Year - DOBPicker.Value.Date.Year) <= 17 Or (Today.Year - DOBPicker.Value.Date.Year) >= 23 Then
MessageBox.Show("Enter a Valid Date.")
End If
End Sub
Private Sub OkButton_Click(sender As Object, e As EventArgs) Handles OkButton.Click
If Not String.IsNullOrEmpty(PasswordTextBox.Text) AndAlso Not String.IsNullOrEmpty(ConfirmPasswordTextBox.Text) Then
Dim connectionString As String = "Data Source=DESKTOP-JI8QG4T\SQLSERVER2022;Initial Catalog=collegestudent;Integrated Security=True"
Using connection As New SqlConnection(connectionString)
Dim query As String = "SELECT * FROM studentreg WHERE StudentId = @studentID AND DOB = @dob"
Using command As New SqlCommand(query, connection)
command.Parameters.AddWithValue("@studentID", _studentID)
command.Parameters.AddWithValue("@dob", DOBPicker.Value.Date)
connection.Open()
If command.ExecuteScalar = Nothing Then
MessageBox.Show("Wrong Date of Birth was entered.")
Close()
Else
query = "UPDATE studentreg SET Password = @pwd WHERE StudentId = @studentID"
Using updateCommand As New SqlCommand(query, connection)
updateCommand.Parameters.AddWithValue("@pwd", PasswordTextBox.Text)
updateCommand.Parameters.AddWithValue("@studentID", _studentID)
updateCommand.ExecuteNonQuery()
MessageBox.Show("Password has been reset successfully.")
Close()
End Using
End If
End Using
End Using
Else
MessageBox.Show("Please Enter the Password correctly.")
End If
End Sub
Private Sub ConfirmPasswordTextBox_Validation(sender As Object, e As EventArgs) Handles ConfirmPasswordTextBox.Validated
If ConfirmPasswordTextBox.Text <> PasswordTextBox.Text Then
MessageBox.Show("Passwords do not match.")
ConfirmPasswordTextBox.Text = ""
Return
End If
End Sub
Private Sub ShowPasswordCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles ShowPasswordCheckBox.CheckedChanged
If ShowPasswordCheckBox.Checked Then
PasswordTextBox.UseSystemPasswordChar = False
ConfirmPasswordTextBox.UseSystemPasswordChar = False
Else
PasswordTextBox.UseSystemPasswordChar = True
ConfirmPasswordTextBox.UseSystemPasswordChar = True
End If
End Sub
End Class