Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL random AND unique password generation?

Posted on 2013-11-08
3
Medium Priority
?
606 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
[X]
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
3 Comments
 
LVL 32

Accepted Solution

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

636 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