1

如何在 ColdFusion 中编写区分大小写的查询?我希望用户名和密码区分大小写。这就是我所拥有的:

<cfquery datasource="myDataSource" name="qVerify">
    SELECT *
      FROM tblUsers
     WHERE userName = '#userName#' 
       AND password = '#password#'
</cfquery>
<cfif qVerify.RecordCount>
    <cfset session.allowin = "True" />
    <cfset session.ID = qVerify.ID />
    { "login" : "valid" }
<cfelse>
    { "login" : "invalid" }
</cfif>

因此,如果用户 Dave(因为它在数据库中)以 dave 身份登录,它将无效......

4

2 回答 2

2

这应该将列视为区分大小写,但您应该真正解决密码存储为纯文本的问题。

<!--- MS SQL Server ---> 
<cfquery datasource="myDataSource" name="qVerify">
SELECT *
FROM tblUsers
WHERE userName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#userName#"> COLLATE SQL_Latin1_General_CP1_CS_A
AND password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#password#"> COLLATE SQL_Latin1_General_CP1_CS_A
</cfquery>

(评论更新)

确切的排序规则名称取决于数据库。对于 MySQL:

<!--- MySQL ---> 
<cfquery datasource="myDataSource" name="qVerify">
SELECT *
FROM tblUsers
WHERE userName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#userName#"> COLLATE latin1_general_cs
AND password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#password#"> COLLATE latin1_general_cs
</cfquery>

有关更多详细信息,请参阅有关 charset/collat​​e 的文档

于 2013-08-30T03:59:47.377 回答
1

将查询中的字段强制转换为区分大小写的类型或使用区分大小写的编码。

于 2013-08-30T03:43:52.863 回答