How to Encrypt a Variable in ColdFusion
Interactive websites often contain pages that gather user information. This information may be something as simple as a username or Web handle, or something much more sensitive. In cases where users are presenting personal information such as passwords or other login credentials, you should implement an encryption method to hide that information from possible theft. In ColdFusion, you can use the "hash" function inside a form to encrypt information before sending it to the database.
Instructions
-
-
1
Create a form using ColdFusion:
<form action="login.cfm" method="post">
username: <input type="text" name="username">
password: <input type="password" name="password">
</form> -
2
Encrypt the password data using the hash function:
<cfquery name="Login" datasource="Mydb">
select * Users
where username = '#form.username#' and password = '#hash(form.password)#'
</cfquery>This encrypts data one way for password authentication. Data encrypted using the hash function cannot be decrypted.
-
-
3
Use the "encrypt" and "decrypt" functions to encrypt data in a way that it can be decrypted:
<cfset encrypted_data = encrypt('string to encrypt', '346')>
<cfset decrypted_data = decrypt(encrypted_data, '346')>
-
1