ColdFusion 9.0 Resources |
Use a login form to get user informationWhen you build an application that gets the User ID and password using a login form, the cflogin tag checks for the existence of a cflogin structure containing the user’s login information. If the structure does not exist, it displays a login form, typically using a cfinclude tag on a login page; the following code shows this use. In the Application.cfc onRequestStart method, or a ColdFusion page or CFC method called by the method, you have the following: <cflogin> <cfif NOT IsDefined("cflogin")> <cfinclude template="loginform.cfm"> <cfabort> <cfelse> <!--- Code to authenticate the user based on the cflogin.user and cflogin.password values goes here. ---> <!--- If User is authenticated, determine any roles and use a line like the following to log in the user. ---> <cfloginuser name="#cflogin.name#" Password = "#cflogin.password#" roles="#loginQuery.Roles#"> </cfif> </cflogin> A simple login form looks like the following: <cfform name="loginform" action="#CGI.script_name#?#CGI.query_string#" method="Post"> <table> <tr> <td>user name:</td> <td><cfinput type="text" name="j_username" required="yes" message="A user name is required"></td> </tr> <tr> <td>password:</td> <td><cfinput type="password" name="j_password" required="yes" message="A password is required"></td> </tr> </table> <br> <input type="submit" value="Log In"> </cfform> |