使用SQL Server控制用户ID和密码 [英] Controlling UserID and password with sql server

查看:134
本文介绍了使用SQL Server控制用户ID和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图形界面,其中包含用户ID和密码文本.我想在SQL Server上存储用户ID和密码,然后在程序中进行控制.我使用哪种方式?我是SQL的新手,所以不了解更多信息.是否有任何SQL查询可以使用数据库来控制它?

I have a graphical interface it has UserID and password texts.I want to store userId ''s and passwords on sql server then control it on program.Which way i use ? I am new at SQL so dont know much more.Is there any sql query to control it with using database ?

推荐答案

这里有一条提示可以告诉您基本知识的密码存储:密码存储:操作方法. [ ^ ]-它并没有告诉您如何将其实际存储在数据库中,但这很容易!

从数据库读取:
There is a tip here that tells you the basics of password storage: Password Storage: How to do it.[^] - it doesn''t tell you how to actually store it in a database, but that is the easy bit!

Read from DB:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT password FROM loginData WHERE userID=@ID", con))
        {
        com.Paramaters.AddWithValue("@ID", userID);
        using (SqlDataReader reader = com.ExecuteReader())
            {
            if (reader.Read())
                {
                byte[] password = (byte[]) reader["password"];
                return password;
                }
            }
        }
    }

写入数据库:

Write To DB:

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO loginData (userID, password) VALUES (@ID, @PW)", con))
        {
        com.Parameters.AddWithValue("@ID", userID);
        com.Parameters.AddWithValue("@PW", password);
        com.ExecuteNonQuery();
        }
    }




在SQL Server中创建一个带有UserID和password字段的表,由于您是SQL的新手,因此无需加密或解密密码

在登录时,读取用户名和密码,如

Hi,

Make a table in SQL server with UserID and password field on it,Since you are new at SQL so you dont have to need to encrypt or decrypt passwords

at Login read the userid and password like

Select * from table where UserID=''"+uid+"'' and password=''"+pwd+"''";


这篇关于使用SQL Server控制用户ID和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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