?
Solved

Create User ID, Registering New User on Website

Posted on 2012-09-07
8
Medium Priority
?
834 Views
Last Modified: 2012-09-07
Instead of having an admin create the users manually through a form, I want the new user to be able to get to the site login and register for a new login ID themselves.  The login ID is a specific format so they can't just go in and create their own ID.  I will have a link there for them to click 'New User' which will bring them to a form to fill out with validation so the form and the values are submitted properly.  The format for the log in ID is as follows:  hid[first letter of first name][first letter of middle name, if none provided it defaults to X][first letter of last name][randomly generated 4 character string].  For instance, in my case, it would be hidlrlzpn1.  The form obviously is going to have fields for First Name, Middle Initial, Last Name, email address, and password.

Is there a good example out there to create this type of ID?  Or can anyone help with the creation of this auto ID?  It will be loaded into the user table with the following parameters:  ID, FNM, MIN, LNM, EML, PSW.
0
Comment
Question by:Lee R Liddick Jr
  • 5
  • 3
8 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 38376765
FirstLetter + FirstLetter + FirstLetter + 4 Letters = 7 chars. The example given ie "hidlrlzpn1" is longer. Is some part of the formula missing?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38376784
Here's an example using the 7 char specs.  It uses the getRandString function from cflib.org


<!--- sample form fields --->
<cfset form.firstName = "Bob">
<cfset form.middleInitial = "">
<cfset form.lastName = "Smith">


<!--- if the middle initial was supplied --->
<cfif len(trim(form.middleInitial))>
      <cfset userName = left(form.firstName, 1) & left(form.middleInitial, 1) & left(form.lastName, 1)>
<cfelse>
      <cfset userName = left(form.firstName, 1) & "X" & left(form.lastName, 1)>
</cfif>

<!--- append random chars --->
<cfset userName = userName & getRandString(4)>

<!--- results --->
<cfoutput> final userName = #userName#</cfoutput>
0
 

Author Comment

by:Lee R Liddick Jr
ID: 38376808
All ID's start with the letters 'hid'...so the total of the login string would be 10.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 52

Expert Comment

by:_agx_
ID: 38376835
(Duh!) Okay, just prepend "hid" at the end:

<!--- generate name portion --->
<cfif len(trim(form.middleInitial))>
      <cfset namePortion = left(form.firstName, 1) & left(form.middleInitial, 1) & left(form.lastName, 1)>
<cfelse>
      <cfset namePortion = left(form.firstName, 1) & "X" & left(form.lastName, 1)>
</cfif>
<!--- generate final id --->
<cfset userName = "hid" & namePortion & getRandString(4)>
<!--- results --->
<cfoutput> final userName = #userName#</cfoutput>
0
 

Author Comment

by:Lee R Liddick Jr
ID: 38376859
so its a getrandstring call that will get me this.  Okay.  So once it creates, I need to bounce it against the current user table to make sure there are no duplicates (I can't imagine that there ever would be) so I can generate the ID, then do a validation query against the user table...if there is a match, how do I loop it back to regenerate another ID?

<!--- generate name portion --->
<cfif len(trim(form.MIN))>
      <cfset namePortion = left(form.FNM, 1) & left(form.MIN, 1) & left(form.LNM, 1)>
<cfelse>
      <cfset namePortion = left(form.FNM, 1) & "X" & left(form.LNM, 1)>
</cfif>
<!--- generate final id --->
<cfset userName = "hid" & namePortion & getRandString(4)>

<!--- get current IDs --->
<cfquery name="chkID">
select ID
from rfw_users
where ID = #userName#
</cfquery>

So obviously, if the query returns 1 (there is a duplicate and I can't do the insert query) so I need to regenerate another ID, so how can I loop it back through if the result is 1 after my check?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 38376974
You need to put it inside a loop. Just repeat the check until it succeeds OR it exceeds the max number of retries.

I'd also put a UNIQUE constraint on that table column to ensure duplicates *can't* be entered period.

<cfset maxRetry = 10>
<cfset retryCount = 0>
<cfset success = false>

<cfloop condition="NOT success and retryCount lt maxRetry">
        <!--- generate a random username code here ...--->
      <cfset userName = "..generate the username code..">
      
      <!--- check if it's in use ---->
       <cfquery name="chkID">SELECT .... </cfquery>

      <!--- If it's not already used ..  ---->
      <cfif chkID.recordCount eq 0>
            success. go ahead and insert it
            <cfset success = true>
      </cfif>

        <!--- this prevents an infinite loop --->
      <cfset retryCount++>
</cfloop>

<cfif success>
        login sucessfully created
<cfelse>
        max retries exceeded. unable to create login
</cfif>
0
 

Author Closing Comment

by:Lee R Liddick Jr
ID: 38377085
I figured it would be a loop, wasn't sure how to actually do it.  You are a lifesaver once again agx!  Thank you...
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38377107
Always a pleasure to help out :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question