⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 修改密码.frm

📁 初学vb,做的第一个系统.一个星期内看vb并做完这个系统的.
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form change_password 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "修改密码"
   ClientHeight    =   2895
   ClientLeft      =   5490
   ClientTop       =   4290
   ClientWidth     =   4380
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   10.5
      Charset         =   134
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   2895
   ScaleWidth      =   4380
   Begin VB.CommandButton Command3 
      Caption         =   "返回"
      Height          =   375
      Left            =   600
      TabIndex        =   10
      Top             =   2280
      Width           =   975
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   120
      Top             =   2760
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=stu_manage"
      OLEDBString     =   "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=stu_manage"
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   "sa"
      Password        =   "manager"
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton Command2 
      Caption         =   "重 置"
      Height          =   375
      Left            =   1860
      TabIndex        =   9
      Top             =   2280
      Width           =   975
   End
   Begin VB.CommandButton Command1 
      Caption         =   "修 改"
      Height          =   375
      Left            =   3120
      TabIndex        =   8
      Top             =   2280
      Width           =   975
   End
   Begin VB.TextBox Text4 
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   1560
      PasswordChar    =   "*"
      TabIndex        =   7
      Top             =   1680
      Width           =   2175
   End
   Begin VB.TextBox Text3 
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   1560
      PasswordChar    =   "*"
      TabIndex        =   6
      Top             =   1200
      Width           =   2175
   End
   Begin VB.TextBox Text2 
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   1560
      PasswordChar    =   "*"
      TabIndex        =   5
      Top             =   720
      Width           =   2175
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1560
      TabIndex        =   4
      Top             =   240
      Width           =   2175
   End
   Begin VB.Label Label4 
      Caption         =   "确认新密码"
      Height          =   255
      Left            =   360
      TabIndex        =   3
      Top             =   1800
      Width           =   1095
   End
   Begin VB.Label Label3 
      Caption         =   "新密码"
      Height          =   255
      Left            =   480
      TabIndex        =   2
      Top             =   1320
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "原密码"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   480
      TabIndex        =   1
      Top             =   840
      Width           =   975
   End
   Begin VB.Label Label1 
      Caption         =   "用户名"
      Height          =   255
      Left            =   480
      TabIndex        =   0
      Top             =   360
      Width           =   975
   End
End
Attribute VB_Name = "change_password"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'修改按钮
Private Sub Command1_Click()
    '将要用到的四个输入变量的声明
    Dim user As String
    Dim oldpwd As String
    Dim newpwd1 As String
    Dim newpwd2 As String
    
    '连接数据库
    Dim rs As New ADODB.Recordset
    Dim adoconn As New ADODB.Connection 'Connection 对象代表了打开与数据源的连接。
    adoconn.ConnectionString = Adodc1.ConnectionString 'Adodc1为窗体中的ADO控件,并已成功连接数据库
    adoconn.Open
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenKeyset
    rs.LockType = adLockOptimistic
    
    '获取用户输入的值
    user = Text1.Text
    oldpwd = Text2.Text
    newpwd1 = Text3.Text
    newpwd2 = Text4.Text
    
    
    '检查输入信息是否有空值或长度过大
    If Len(user) = 0 Then
        MsgBox "请输入用户名!"
        Text1.SetFocus
        Exit Sub
    ElseIf Len(oldpwd) = 0 Then
        MsgBox "请输入原密码!"
        Text2.SetFocus
        Exit Sub
    ElseIf Len(newpwd1) <= 5 Then
        MsgBox "密码长度不能少于6位,请重新设置!"
        Text2.Text = ""
        Text3.Text = ""
        Text4.Text = ""
        Text2.SetFocus
        Exit Sub
    ElseIf Len(newpwd2) = 0 Then
        MsgBox "请确认你的新密码!"
        Text4.Text = ""
        Text4.SetFocus
        Exit Sub
    ElseIf Len(newpwd1) >= 17 Then
        MsgBox "密码至多只允许16位,请重新设置!"
        Text2.Text = ""
        Text3.Text = ""
        Text4.Text = ""
        Text2.SetFocus
        Exit Sub
    End If
    
    '判断是否已经存在,若存在则转向userexists
    rs.Open "select * from admin", adoconn
    For i = 0 To rs.Fields.Count - 1
        If user = rs.Fields("id") Then
            GoTo userexists
        End If
    Next i
    
    '没有转向userexists,则用户不存在
    MsgBox "没有该用户!"
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text1.SetFocus
    Exit Sub
    
    '用户存在
userexists:
    '原密码不正确,不能修改
    If oldpwd <> rs.Fields("pwd") Then
        rs.Close
        MsgBox "原密码不正确,您不能修改密码!"
        Text2.Text = ""
        Text3.Text = ""
        Text4.Text = ""
        Text2.SetFocus
        Exit Sub
    '原密码正确,可以修改
    Else
        '新输入的两次密码不同
        If newpwd1 <> newpwd2 Then
            rs.Close
            MsgBox "您两次输入的密码不一致,请重试!"
            Text2.Text = ""
            Text3.Text = ""
            Text4.Text = ""
            Text2.SetFocus
            Exit Sub
        Else
            rs.Close
            rs.Open "select * from admin where id='" & user & "'", adoconn
            rs.Fields("pwd") = newpwd1
            rs.Update
            rs.Close
            adoconn.Close
            MsgBox "密码修改成功!"
            Unload Me
            login.Show
        End If
    End If
    
End Sub
'重置按钮
Private Sub Command2_Click()
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text1.SetFocus
End Sub
'返回按钮
Private Sub Command3_Click()
    Unload Me
    login.Show
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -