SQL random AND unique password generation?

Posted on 2013-11-08
Medium Priority
Last Modified: 2013-11-08
I have found many examples of SQL random password generators but nothing that will check whether it is unique.

I am generating a username/password for security on a public system. The username is an email and the initial password needs to be randomly generated and not equal to any existing password held on my user security table.

I am pretty sure that some one must have a function already?

Any help would be greatly appreciated.

Question by:splanton
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 32

Accepted Solution

Ephraim Wangoya earned 2000 total points
ID: 39633152
You can use a loop to check if the password exists in the table
Suppose your function to generate password is ufn_GeneratePassword

You could create a SP that checks the password

create sp_GetUniquePassword(out @password varchar(max))
   declare @temp varchar(max) = ''
   while Exists(select 1 from UserSecuritytable where PasswordField = @temp)
     select @temp = dbo.ufn_GeneratePassword
   set @password = @temp

Expert Comment

ID: 39633294
If you generated something based on the current full date time down to the millisecond, that is almost certain to be unique...

If you need some help with code to to that, give us a shout



Author Closing Comment

ID: 39633331
That's the ticket. I was thinking of creating a second while loop but had no idea on the best way to go about it. Many thanks.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

770 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