Solved

SQL random AND unique password generation?

Posted on 2013-11-08
3
543 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

863 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

22 Experts available now in Live!

Get 1:1 Help Now