?
Solved

SQL Statement checking for restricted username

Posted on 2005-04-14
2
Medium Priority
?
284 Views
Last Modified: 2006-11-18
I've a problem here which is, IF let say when somebody signup with the username of 'adminForever'

How do i restrict him from using the "ADMIN" in his username or others name that listed in my table "tblrestrictedname"???
How do i compare it?

declare @username as nvarchar(50)
set username='adminForever'

if not exists(select * from tblmember where username like @username) ???
0
Comment
Question by:dynamicrevolutions
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 2000 total points
ID: 13782796
Try this one:

declare @username as nvarchar(50)
set @username='adminForever'

IF EXISTS (SELECT * FROM tblRestrictedName
WHERE UserName LIKE '%' + @username + '%' OR
           @UserName LIKE '%' + UserName + '%')
--- Not Allowed
0
 
LVL 23

Expert Comment

by:adathelad
ID: 13782827
declare @username as nvarchar(50)
set @username='adminForever'

IF NOT EXISTS(SELECT 1 FROM tblRestrictedName WHERE @username LIKE '%' + Name + '%')
    BEGIN
        -- Allow username to be used
    END

This will check whether any restricted names appear *anywhere* in the username.
So, if "admin" was listed in tblRestrictedName, it would rule out "adminForever", "Foreveradmin", "Hadmint" etc etc
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

850 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