Solved

SQL random AND unique password generation?

Posted on 2013-11-08
3
538 Views
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.

Regards,
0
Comment
Question by:splanton
3 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 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))
as
begin
   declare @temp varchar(max) = ''
   while Exists(select 1 from UserSecuritytable where PasswordField = @temp)
     select @temp = dbo.ufn_GeneratePassword
   set @password = @temp
end
0
 
LVL 2

Expert Comment

by:aheddell
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

Cheers

Alex
0
 
LVL 2

Author Closing Comment

by:splanton
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.

Regards,
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now