Link to home
Start Free TrialLog in
Avatar of Lee R Liddick Jr
Lee R Liddick JrFlag for United States of America

asked on

Create User ID, Registering New User on Website

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.
Avatar of _agx_
_agx_
Flag of United States of America image

FirstLetter + FirstLetter + FirstLetter + 4 Letters = 7 chars. The example given ie "hidlrlzpn1" is longer. Is some part of the formula missing?
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>
Avatar of Lee R Liddick Jr

ASKER

All ID's start with the letters 'hid'...so the total of the login string would be 10.
(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>
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?
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I figured it would be a loop, wasn't sure how to actually do it.  You are a lifesaver once again agx!  Thank you...
Always a pleasure to help out :)