在VB 10中创建一个区分大小写的登录表单 [英] Create a Case Sensitive Login Form in VB 10

查看:92
本文介绍了在VB 10中创建一个区分大小写的登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个登录表单,密码中的字段区分大小写,如果我的密码是PassWord,它只接受关键字PassWord而不接受password或PASSWORD关键字等。我想要它是一个字符敏感谢谢请帮助我我是一个新的程序员使用数据库MS访问谢谢这里是我的代码问题是我无法创建一个登录表单,密码字段区分大小写

I want to Create a Login Form that the fields in password are case sensitive example if my passwords is "PassWord" it will only accepts the keyword "PassWord" and not accepts "password" Or "PASSWORD" keyword etc. I want it a character sensitive thanks Please Help me Im a new Programmer using DATABASE MS ACCESS Thanks Here is my code The Problem is i can't create a log in form that the password field is case sensitive

Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click
    Try
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\NIASecurity.accdb")
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT [Username] FROM [Security] WHERE [Username] = @User and Password =@Pass ", con)
        cmd.Parameters.AddWithValue("@User", txtUser.Text)
        cmd.Parameters.AddWithValue("@Pass", txtPass.Text)
        con.Open()
        Dim sdr As OleDbDataReader = cmd.ExecuteReader()
        If sdr.Read Then
            If txtPass.Text = sdr(0) Then
                MessageBox.Show("Welcome")
                Dim win As New frmAdd
                win.MdiParent = frmMDI
                win.Show()
                Me.Close()
            Else
                MsgBox("Invalid name or password!")

            End If
        End If


    Catch ex As Exception
        MessageBox.Show("Invalid name or password!")
    End Try
End Sub

推荐答案

仔细阅读SA的评论!它向您解释为什么在密码中您不需要关心区分大小写或不敏感! HelloWorld的哈希值与helloworld不同!

对于其他数据(如您的情况下的名称),如果您需要区分大小写的数据,则必须选择正确的 COLLATION [ ^ ]您的数据库或使用 COLLATE [ ^ ]在单个数据列/变量上,根据您的需要使其区分大小写或不敏感!!! />


让我们看看一些样本...

想象一下,我们有一个数据库,其中包含了Latin1_General_CI_AS的整理,这意味着unicode的Latin1部分不区分大小写,口音敏感的比较...

现在我们有一个包含两列的表(Usr) - PswHash,UserN ame。

如果我们想要比较UserName区分大小写(记住DB是不敏感的情况!)我们可以这样做......

Read extremely carefully SA's comment! It explain to you why in password you need not care for case-sensitive or insensitive! A hash of HelloWorld is not the same as of helloworld!
For other data (like names in your case) if you want case-sensitive data, you have to choose the right COLLATION[^] for your database or use COLLATE[^] on a single data column/variable to make it case-sensitive or insensitive according your need!!!

Let see some sample...
Imagine we have a database with collation of Latin1_General_CI_AS, which means the Latin1 portion of unicode with case insensitive and accent sensitive comparison...
Now we have a table (Usr) with two columns - PswHash, UserName.
If we want to compare UserName case sensitive (remember the DB is case INsensitive!) we can do it like this...
SELECT *
FROM Usr
WHERE UserName = @UserName COLLATE Latin1_General_CS_AS;



其中@UserName是保存用户在登录表单上写的用户名的变量...


Where @UserName is the variable holding the user name as written by the user on the login form...


这篇关于在VB 10中创建一个区分大小写的登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆