• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

SQL Statement checking for restricted username

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
dynamicrevolutions
Asked:
dynamicrevolutions
1 Solution
 
rafranciscoCommented:
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
 
adatheladCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now