making sure password is unique

below I have a code that creates a new password, checks for duplicates and creates a new one if duplicate....then stops.

The chances of duplicates are slim afterwards but wouldn't there be a way to loop until unique?
Not sure how to do this.
<cfset newpword=left(createUUID(),8)>
<cfquery name="verifynewPW" datasource="#application.DSHome#" username="#application.dbuserHome#"
password="#application.dbpassHome#">
		SELECT *
		FROM members
		WHERE password =<CFQUERYPARAM Value="#newpword#">
		</cfquery>
        
<cfif verifynewPW.RecordCount IS not 0 >
<cfset newpword=left(createUUID(),8)>
</cfif>

Open in new window

LVL 1
ShawnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PluckaCommented:
Use a conditional loop which will repeat white the condition is met.

<cfloop condition="uniquePassword eq false">

</cfloop>
0
ShawnAuthor Commented:
ok, but I'm not sure how I would integrate that with the above code.
0
azadisaryevCommented:
<cfset PwdIsUnique = false>
<cfloop condition="PwdIsUnique is false">
  <cfset newpword=left(createUUID(),8)>
  <cfquery name="verifynewPW" datasource="#application.DSHome#" username="#application.dbuserHome#"
password="#application.dbpassHome#">
  SELECT password
  FROM members
  WHERE password =<CFQUERYPARAM Value="#newpword#">
  </cfquery>
  <cfif verifynewPW.RecordCount IS 0 >
    <cfset PwdIsUnique = true>
  </cfif>
</cfloop>
<!--- change below line to whatever you need to do when a password IS unique --->
<cfoutput>#newpword#</cfoutput>

Azadi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

ShawnAuthor Commented:
brilliant Azadi. thanks again
0
_agx_Commented:
This kind of logic is usually better off in a stored procedure.  However, if choose to do it with cf code keep in mind that CF is multi-threaded.  So there is still a small possibility of duplicates using this type of structure in applications with a high level of concurrency.  (Though much less in this case, as you are using UUID to create the value.)  To be safe, you should also create a unique index on your password column. That will reject any attempt to insert a duplicate. Then use cftry/cfcatch if needed.

0
ShawnAuthor Commented:
thanks for the extra info _agx_: It is already a unique index. As I'm just coming from Access and have very little experience with stored procedures I didn't attempt this. I'd like to learn it though. Should I open another question for this?
0
_agx_Commented:
Good.  As long as you have the unique index, to prevent any attempt to insert a duplicate, you are in good shape.

Yes, I would open another question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.