Я пытаюсь создать безопасную область входа в систему с помощью Coldfusion, где имя пользователя, пароль и user_id (возможно, с использованием CFParam URL.user_id) определяют, какая информация отображается после входа в систему — что-то вроде онлайн-аккаунта. Таким образом, используя свои собственные учетные данные для входа, пользователь будет входить в систему и иметь доступ к своей информации ТОЛЬКО без страниц по умолчанию для первого пользователя в базе данных или путем доступа к информации другого пользователя, просто изменив user_id в браузере. bar (возможно, зашифровав переменные URL). Вот то, что я всегда использовал для безопасного входа в систему в прошлом (который работает), который также имеет 3 неудачных попытки входа в систему и сеанс тайм-аута:
<cfquery name="rs_user" datasource="source">
SELECT user_id
FROM table
WHERE user_id = <cfqueryparam value="#URL.user_id#" cfsqltype="cf_sql_integer">
</cfquery>
<cfif IsDefined("URL.MM_logout") AND URL.MM_logout EQ "1">
<cflock scope="Session" type="Exclusive" timeout="30" throwontimeout="no">
<cfset Session.MM_Username="">
<cfset Session.MM_UserAuthorization="">
</cflock>
<cfset MM_logoutRedirectPage="index.cfm">
<cfif MM_logoutRedirectPage EQ "">
<cfset MM_logoutRedirectPage=CGI.SCRIPT_NAME>
</cfif>
<cfset MM_logoutQuery=ListDeleteAt(CGI.QUERY_STRING,ListContainsNoCase(CGI.QUERY_STRING,"MM_logout=","&"),"&")>
<cfif MM_logoutQuery NEQ "">
<cfif Find("?",MM_logoutRedirectPage) EQ 0>
<cfset MM_logoutRedirectPage=MM_logoutRedirectPage & "?" & MM_logoutQuery>
<cfelse>
<cfset MM_logoutRedirectPage=MM_logoutRedirectPage & "&" & MM_logoutQuery>
</cfif>
</cfif>
<cflocation url="#MM_logoutRedirectPage#" addtoken="no">
</cfif>
<cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
<cfif IsDefined("FORM.loginfield")>
<cfset MM_redirectLoginSuccess="table/landing_page.cfm?user_id=#rs_user.user_id#">
<cfset MM_redirectLoginFailed="#CurrentPage#?loginfailed=True&loginfield=#form.loginfield#">
<cfset variables.blnAllowLogin=false>
<cfset variables.isLocked=false>
<!--- lets find the user --->
<cfquery name="qryUserAttempts" datasource="source">
SELECT
user_id,
dateLocked,
failedLoginAttempt
FROM
table
WHERE
username=<cfqueryparam value="#FORM.loginfield#" cfsqltype="cf_sql_varchar" maxlength="255">
</cfquery>
<cfif qryUserAttempts.recordcount>
<cfif isDate(qryUserAttempts.dateLocked)>
<cfset intMinSinceLocked=DateDiff("n",qryUserAttempts.dateLocked,now())>
<!--- number of mins to lock (set to 5) --->
<cfif intMinSinceLocked GT 5>
<cfset variables.blnAllowLogin=true>
<cfelse>
<cfset variables.isLocked=true>
</cfif>
<cfelse>
<cfset variables.blnAllowLogin=true>
</cfif>
<cfelse>
<cfset variables.blnAllowLogin=true>
</cfif>
<cfif variables.blnAllowLogin>
<cfquery name="MM_rsUser" datasource="source">
SELECT user_id, username, password
FROM table
WHERE username=<cfqueryparam value="#FORM.loginfield#" cfsqltype="cf_sql_varchar" maxlength="255">
AND password=<cfqueryparam value="#FORM.password#" cfsqltype="cf_sql_varchar" maxlength="255">
</cfquery>
<cfif MM_rsUser.RecordCount>
<cflock scope="Session" timeout="30" type="Exclusive">
<cfset Session.MM_Username=FORM.loginfield>
<cfset Session.MM_UserAuthorization=MM_rsUser.user_id[1]>
</cflock>
<cfset MM_redirectLoginSuccess="table/landing_page.cfm?user_id=#rs_user.user_id#">
<cfquery name="qryUserAttemptsSuccessful" datasource="source">
UPDATE table
SET
failedLoginAttempt=0
,dateLocked=NULL
WHERE
user_id=<cfqueryparam value="#qryUserAttempts.user_id#" cfsqltype="cf_sql_integer">
</cfquery>
<cflocation url="#MM_redirectLoginSuccess#" addtoken="no">
<!--- <cfelse>
<cfif ArrayLen(Session.MM_rsUser.attempts) GTE 3><h2>You've exceeded your login attempts. Please try again later.</h2>
<cfabort>
<cfelse>
<cfset ArrayAppend(Sessionm.MM_rsUser.attempts,Now())>
</cfif> --->
<cfelse>
<cfset variables.failedLoginAttempt="">
<cfif qryUserAttempts.recordcount>
<cfif isNumeric(qryUserAttempts.failedLoginAttempt)>
<cfset variables.failedLoginAttempt=qryUserAttempts.failedLoginAttempt+1>
<cfelse>
<cfset variables.failedLoginAttempt=1>
</cfif>
<cfquery name="qryUserAttempts" datasource="source">
UPDATE table SET
failedLoginAttempt=<cfqueryparam value="#variables.failedLoginAttempt#" cfsqltype="cf_sql_integer">
<cfif variables.failedLoginAttempt GTE 3>
,dateLocked=<cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">
</cfif>
WHERE
user_id=<cfqueryparam value="#qryUserAttempts.user_id#" cfsqltype="cf_sql_integer">
</cfquery>
</cfif>
<cflocation url="#MM_redirectLoginFailed#&failedLoginAttempt=#variables.failedLoginAttempt#" addtoken="no">
</cfif>
<cfelse>
<cflocation url="#MM_redirectLoginFailed#&accountlocked=true" addtoken="no">
</cfif>
<!--- End code for handling failed login attempts
<cfif IsDefined("URL.accessdenied") AND true>
<cfset MM_redirectLoginSuccess=URL.accessdenied>
</cfif>
<cflocation url="#MM_redirectLoginSuccess#" addtoken="no">
</cfif>
<cflocation url="#MM_redirectLoginFailed#" addtoken="no">
<cfelse> --->
</cfif>
<cfset MM_LoginAction=CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ "">
<cfset MM_LoginAction=MM_LoginAction & "?" & XMLFormat(CGI.QUERY_STRING)>
</cfif>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Microdata markup added by Google Structured Data Markup Helper. -->
<html xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
<head>
<title>login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
#target-content {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
pointer-events: none;
opacity: 0;
-webkit-transition: opacity 200ms;
transition: opacity 200ms;
z-index:3000;
}
#target-content:target {
pointer-events: all;
opacity: 1;
}
#target-content #target-inner {
position: absolute;
display: block;
padding-left: 30px;
padding-right:48px;
padding-top:30px;
padding-bottom:48px;
line-height: 1.8;
width: 45%;
top: 50%;
left: 50%;
-webkit-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
box-shadow: 0px 12px 24px rgba(0, 0, 0, 0.2);
background: white;
color: #34495E;
}
#target-content #target-inner h2 { margin-top: 0; }
#target-content #target-inner code { font-weight: bold; }
#target-content a.close {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #000;
opacity: 0.7;
-webkit-transition: opacity 200ms;
transition: opacity 200ms;
}
#target-content a.close:hover { opacity: 0.7; }
input[type=submit] {
-webkit-appearance: none;
}
.button_login {
font: 16px/22px "Open Sans", Arial, sans-serif;
display: inline-block;
color: #FFF;
text-transform: uppercase;
display:inline-block;
padding:12px 20px 12px 23px;
font-weight:500;
text-decoration:none;
border:none;
position:relative;
z-index:1;
background-color: #77bc1f;
}
.button_login:hover {
text-decoration:none;
background-color: #7d868c;
color:#fff;
}
</style>
</head>
<body>
<h2 style="text-align:left;">LOGIN</h2>
<cfif IsDefined("URL.loginfailed")>
<h5 style="text-align:left;">Authentication failed. <br />Please try again.</h5>
</cfif>
<cfif StructKeyExists(URL,"accountlocked")><h5 style="text-align:left;">You've exceeded your login attempts.<br />Please try again later.</h5></cfif>
<form id="loginform" name="loginform" method="POST" action="<cfoutput>#MM_loginAction#</cfoutput>">
<h5 style="margin-top:20px; color:#686868; margin-bottom:5px;" >Username: </h5>
<input name="loginfield" type="text" id="loginfield" style="font-size:18px; font-weight: 300; width:100%; height:30%; border:none; padding-right:10px; padding-left:10px; padding-top:5px; padding-bottom:5px; position:relative; z-index:1; font-family: Tahoma, sans-serif; background: #f5f6f6; color:#7d868c; text-align:left; border-radius:0; -webkit-appearance: none;" />
<h5 style="margin-top:20px; color:#686868; margin-bottom:5px;" >Password:</h5>
<input name="password" type="text" id="password" style="font-size:18px; font-weight: 300; width:100%; height:30%; border:none; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; position:relative; z-index:1; font-family: Tahoma, sans-serif; background: #f5f6f6; color:#7d868c; text-align:left; margin:0; -webkit-appearance: none; border-radius:0;"/></h4>
<input name="login" type="submit" id="login" value="LOGIN" />
</form>
</body>
</html>
...AND password=<cfqueryparam value="#FORM.password#" cfsqltype="cf_sql_clob" maxlength="255">
указывает на то, что вы можете хранить пароль в открытом виде. Если да, то это очень и очень плохо. Только один человек должен знать пароль в открытом виде — пользователь. Если его может увидеть или восстановить кто-то другой, это невероятно небезопасно. - person Shawn   schedule 24.01.2019clob
для ее хранения. - person Shawn   schedule 24.01.2019table/landing_page.cfm?user_id=#UseTheVeryFirstUserIDInTheQueryResults#
. Однако, как указал @JamesAMohler, вы должны использовать переменные сеанса, а не передавать идентификатор в URL-адресе (который можно подделать). В конечном счете, не полагайтесь на код, сгенерированный мастером. Обычно он раздут и не предназначен для обеспечения безопасности/лучших практик ;-) - person SOS   schedule 25.01.2019<cfset session.user_id = 1234>
. Используете ли вы в настоящее время Application.cfm/cfc? Дополнительные сведения о переменных сеанса см. в разделе helpx.adobe.com/coldfusion/developing-applications/ - person SOS   schedule 25.01.2019<cfset Session.user_id = rs_user.user_id
› в свой Application.cfm, как было предложено, но это должно быть неправильно. Это не работает. :-( - person user3067421   schedule 26.01.2019