在登录期间使用sql server验证asp.net中的区分大小写的密码

时间:2012-04-05 17:38:35

标签: asp.net sql-server sql-server-2008 sql-server-2005 c#-4.0

返回成功

Dim user = "ravi"
        Dim pass = "admin"
        objcmd.CommandText = "Select * from ADMIN_INFO where ADMIN_ID='" & user & "' and ADMIN_PASS='" & pass & "'"

返回成功

Dim user = "ravi"
        Dim pass = "ADMIN"
        objcmd.CommandText = "Select * from ADMIN_INFO where ADMIN_ID='" & user & "' and ADMIN_PASS='" & pass & "'"

执行查询后,两者都返回成功,而表中只有raviadmin可用。那么,我该如何检查区分大小写。需要帮助!!

2 个答案:

答案 0 :(得分:2)

CREATE TABLE #temp
(
    Password Varchar(2)
)
insert into #temp values('a')

第一种方法

select Password  from #temp Where Password COLLATE Latin1_general_CS_AS  = 'A' 
select Password  from #temp Where Password COLLATE Latin1_general_CS_AS  = 'a' 

第二种方法

select Password  from #temp Where cast(Password as varbinary(2))  = cast('A' as varbinary(15)) 
select Password  from #temp Where cast(Password as varbinary(2))  = cast('a' as varbinary(15)) 

drop table #temp

答案 1 :(得分:2)

本文可能会对您有所帮助:Case sensitive search in SQL Server queries。但是,通常不能以纯文本格式保存密码。

此外,您可以从数据库中选择admin行,然后在.Net端进行密码比较,默认情况下比较区分大小写。

bool result = string1.Equals(string2); //this is case sensitive unless you specify otherwise