我正在使用CFLDAP讓用戶使用活動目錄進行身份驗證。我正在嘗試編寫一條if語句,以防用戶信息未經過身份驗證。我想我可以使用<cfif AuthenticateUser.RecordCount gt 0>
進行檢查,只要信息是正確的,但是如果輸入了錯誤的信息並且沒有任何驗證,它就不會運行else語句。任何幫助,將不勝感激!如果Else查詢爲空
<cfldap action="query"
name="AuthenticateUser"
attributes="dn,mail,givenname,sn,samaccountname,memberof"
start="DC=domain,DC=net"
filter="(&(objectclass=user)(samAccountName=#trim(form.user_name)#))"
server="servername"
Port="389"
username="tc\#trim(form.user_name)#"
password="#trim(form.user_pass)#">
<cfoutput>#AuthenticateUser.RecordCount#</cfoutput>
<!--- Get all records from the database that match this users credentials --->
<cfquery name="userVerify" datasource="test">
SELECT *
FROM dbo.Users
WHERE user_name = <cfqueryparam value="#AuthenticateUser.samaccountname#" cfsqltype="cf_sql_varchar" />
</cfquery>
<cfif AuthenticateUser.RecordCount gt 0>
<!--- This user has logged in correctly, change the value of the session.allowin value --->
<cfset session.allowin = "True" />
<cfset session.employee_number = userVerify.employee_number />
<!--- Now welcome user and redirect to "index.html" --->
<script>
self.location="../dashboard/dashboard.cfm";
</script>
<cfelse>
<!--- this user did not log in correctly, alert and redirect to the login page --->
<script>
alert("Your credentials could not be verified, please try again!");
self.location="Javascript:history.go(-1)";
</script>
</cfif>
我也曾嘗試:<cfif len(AuthenticateUser)>
當發生這種情況時,AuthenticateUser包含什麼?其他查詢的用途是什麼,即userVerify? – Leigh
當它的身份驗證是抓取所有活動目錄信息時,輸入錯誤的登錄名時,它只是空白。 userVerify基本上將認證名稱與sql數據庫進行匹配,獲取所有用戶信息,如員工編號和全部。許多事情不在活動目錄 –
所以當我輸入正確的用戶名和密碼時,它會繼續並轉到我的控制面板cfm,但是當我輸入錯誤的信息時,我只是得到一個白色屏幕,並且它不顯示任何內容authenticateuser –