virtix / cfcrypto

cipher stuff for coldfusion

This URL has Read+Write access

cfcrypto / AddUserAction.cfm
100644 65 lines (44 sloc) 1.772 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<style>body{font-family:courier new}</style>
<cfparam name="form.name" default="" />
    <cfparam name="form.username" default="" />
<cfparam name="form.password" default="" />
 
    
<!--------------------------------------------------------------------------------
                        //Begin
 --------------------------------------------------------------------------------->
 
<!---// Get the utility object --->
<cfset crypto = createObject('component' ,'Crypto') />
<cfset salt = crypto.genSalt() />
    <!---// Get user password hash and salt from db --->
<cfset passwordHash = crypto.computeHash(form.password, salt) />
    <cfset sql = htmlEditFormat('
    <cfquery name="addUser" datasource="myDatasource">
       INSERT INTO USERS
       
       (id,
        name,
        username,
        password_hash,
        salt)
        
       VALUES
       
       (''#createUUID()#'',
        ''#form.name#'',
        ''#form.username#'',
        ''#passwordHash#'',
        ''#salt#'')
    </cfquery>
                
      ')/>
 
    
    
<div align="center"> <strong>Example SQL Statement</strong><br />
    for adding hashed password and salt to a database.
        
    <pre style="text-align:left;padding-left:120">
    <cfoutput>
     #sql#
    </cfoutput>
   </pre>
 
<p><a href="AddUserForm.cfm">Try Another?</a></p>
    <p><a href="LoginForm.cfm">Try Login Example?</a></p>
  
  </div>
 
<!--------------------------------------------------------------------------------
                         //End
 --------------------------------------------------------------------------------->
 
 
<p><hr size="1" noshade="true" /></p>
<h4 align="center">Debug Info</h4>
 
<cfdump var="#form#" label="You submitted the following data:">