SQL检查密码是对还是错 [英] SQL check if password was right or wrong

查看:63
本文介绍了SQL检查密码是对还是错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个SQL CE数据库.密码必须由用户提供.问题是当我连接到数据库时,找不到任何方法可以检查给定的密码是否正确.

Hi,
I have a SQL CE database. the password have to be given by user. The problem is when I connect to database, I find no way to check if the given password is corrected or not.

public partial class UsersDB : DataContext
{
    public Table<Users.UserLoginData> UsersTable = null;
    public UsersDB(string connection, string password): base(connection)
    {
        if (!DatabaseExists())
            CreateDatabase();
        bool endLoop = false;
        while(!endLoop)
        {
            if (password != "")
            {
                try
                {
                     base.Connection.ConnectionString ="datasource="+ connection
                    + "; Password=" + password;
                }
                catch(Exception ex)
                {
                     MessageBox.Show("Wrong connection type");
                }
               ....



尝试访问数据之前,错误的密码不会引发异常.另外,我不确定以前的方式是否是业余爱好者:



Wrong password does not throw an exception until a try to accessing data happens. Also I''m not sure if my previous way was an amateur or not:

try
{
    UsersTable.Count();
    endLoop = true;
}
catch(System.Data.SqlServerCe.SqlCeException ex)
{
    if (ex.Message.ToLower().IndexOf("password") >= 0)
    {
        ....


如果我想将类更改为基类,则没有有关派生类中的表的信息.
作为基类,不能使用像此处的"UsersTable"之类的表.

有人可以帮我吗?


If I want to change the class to a base class I have no information about tables in derived classes.
As a base class it is not possible to use Tables such as "UsersTable" like here.

Can anyone help me?

推荐答案

查找密码是否不正确的唯一方法是执行一个简单的查询....类似选择顶部1 1来自sys.objects''或类似的东西...并添加错误处理以捕获不正确的密码错误

制作一个函数(checkConnection),该函数执行一些简单的查询并根据是否捕获到错误的登录错误分别返回true或false.
The only way to find if the password is incorrect is by executing a simple query....something like ''select top 1 1 from sys.objects'' or something like that...and adding error handling to catch a incorrect password error

Make a function (checkConnection) which executes some such simple query and returns true or false depending on whether the incorrect login error is caught or not respectively.


这篇关于SQL检查密码是对还是错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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