• home
  • forum
  • my
  • kt
  • download
  • Coldfusion Login Script

    Author: 2009-02-27 10:15:58 From:

    Here i am going to show you how to make a login script that will check users against a database for the user name and password.

    First of all we will need to make a login form, this is just going to be a basic form with a user name field, password field and a login button

    <form id="Login" action="login_action.cfm" method="post" name="Login">
    <table cellspacing="0" cellpadding="0" width="300" align="center" border="0">
    <tbody>
    <tr>
    <td colspan="2">
    <div class="style2" align="center"><strong>Login</strong></div>
    </td>
    </tr>
    <tr>
    <td>Username</td>
    <td><input id="Username" name="Username" type="text" /></td>
    </tr>
    <tr>
    <td>Password</td>
    <td><input id="Password" type="password" name="Password" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit" /></td>
    </tr>
    </tbody>
    </table>
    </form>

    Now we have the form we need check the form and see if the user exists and that there password is correct. If the details are not correct they will be sent back to the login page.

    If the details are correct then we will set there user name as a session variable so that it can be used in the site, and we will send them to the secure page.

    <cfquery datasource="Users" name="Login">SELECT * FROM users WHERE username = '#FORM.username#' AND password = '#FORM.username#' <cfif is="" login.recordcount=""><cflocation addtoken="No" url="login.cfm?badlogin=1"><cfelse><cfset session.loggedin="1"><cfset session.username="#Login.username#"><cflocation url="/index.cfm">

    As you can see this is a very basic script, but it is all you need to get started. I will soon be covering how to store encrypted passwords in your database and how to add roles to the users.

    discuss this topic to forum

    relation tutorial

    No information

    New

    Hot