开发实践教程1:试卷生成系统6.20 密码修改(FormPass)
Posted VB.Net
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开发实践教程1:试卷生成系统6.20 密码修改(FormPass)相关的知识,希望对你有一定的参考价值。
版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
用户可以修改密码。
窗体设计如下:
图1-30
具体代码如下:
Imports System.Data.SqlClient
Public Class FormPass
Dim connection As SqlConnection
Private Sub FormUser_Load(sender As Object, e As EventArgs) Handles MyBase.Load
connection = New SqlConnection(databaseConnString)
connection.Open()
txtName.Text = loginName
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Dim passOld As String = txtPassOld.Text.Trim
Dim passNew As String = txtPassNew.Text.Trim
If passNew.Length < 6 Then
MessageBox.Show("密码长度至少应为6位")
Exit Sub
End If
Dim passOldMd5 As String = clsMd5.toMD5(passOld)
Dim passNewMd5 As String = clsMd5.toMD5(passNew)
Dim command As New SqlCommand()
command.CommandText = "select 密码 from 用户表 where 编号=" & loginId
command.Connection = connection
Dim odReader As SqlDataReader
Dim pass As String
odReader = command.ExecuteReader(CommandBehavior.SingleResult)
odReader.Read()
pass = odReader.GetValue(0)
odReader.Close()
If pass <> passOldMd5 Then
MessageBox.Show("原密码不正确,取消操作")
Exit Sub
End If
command.CommandText = "update 用户表 set 密码='" & passNewMd5 & "' where 编号=" & loginId
command.ExecuteNonQuery()
MessageBox.Show("修改密码成功!")
End Sub
Private Sub FormPass_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
connection.Close()
End Sub
End Class
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供的参考。
学习更多vb.net知识,请参看 vb.net 教程 目录
以上是关于开发实践教程1:试卷生成系统6.20 密码修改(FormPass)的主要内容,如果未能解决你的问题,请参考以下文章
开发实践教程1:试卷生成系统6.16 试卷类型管理(FormPaperType)
开发实践教程1:试卷生成系统6.8 试卷信息(FormTestPaperInfo)
开发实践教程1:试卷生成系统6.14 更新试卷信息(FormPaperInfoUpdate)