redshot redshot - 7 months ago 14
HTML Question

How to insert password as Hash to Ms SQL in coldfusion?

I am creating a form that saves a user registration. I want to insert the password to the database as hash or md5.

This is my html form with few coldfusion codes:

<form id="myForm" class="ui form segment" method="post" action="registeraction.cfm">
<p>Let's go ahead and get you signed up.</p>

<div class="field">
<div class="field">
<label>Name</label>
<input placeholder="Name" name="name" type="text">
</div>
</div>

<div class="field">
<div class="field">
<label>Email</label>
<input placeholder="Email" name="email" type="email">
</div>
</div>

<div class="field">
<div class="field">
<label>Password</label>
<input placeholder="Password" name="password" type="password">
</div>
</div>


<input class="ui blue submit button" type="Submit" value="Submit">
</form>


This is the code in registeraction.cfm :

<!--- Insert the new record --->
<cfinsert datasource="mydatasource" tablename="Users">

<h1>User Added</h1>
<cfoutput> You have added #Form.name# #Form.email# to the testdb database.
</cfoutput>

Answer

I think this should work for you. in registeraction.cfm just create hash and store it in form.password (I would recommend using CFC for any business logic and use cfm for only presentation )

  <cfset form.password  = Hash(Form.password, "SHA") > 
   <!--- Insert the new record ---> 
  <cfinsert datasource="mydatasource" tablename="Users"> 

 <h1>User Added</h1> 
 <cfoutput> You have added #Form.name#       #Form.email# to the testdb database. 
</cfoutput>