Great article!
Here are a couple ways to check to make sure there is a mix of upper and lower case letters.
Use the LOWER function. This only ensures that there is at least one upper case character. Use like this:
if @password = LOWER (@password)
-- Password has no upper-case characters
If you want to count how many of each character type, include this in your function/procedure (Assumes a string variable @password is passed in):
declare @lowerCount int
declare @upperCount int
declare @numberCount int
declare @specialCount int
declare @currentIndex int
declare @currentCharAscii int
set @currrentIndex = 0
while @currIndex < LEN (@password)
begin
@currentCharAscii = ASCII (SUBSTRING (@password, @currentIndex, 1))
if @currentCharAscii between 97 and 122 set @lowerCount = @lowerCount + 1
if @currentCharAscii between 65 and 90 set @upperCount = @upperCount + 1
if @currentCharAscii between 48 and 57 set @numberCount = @numberCount + 1
end
set @specialCount = LEN (@password) - @lowerCount - @upperCount - @numberCount
-- Check your rules
You might need to debug typing errors in the code snippet since I did not actually write it in QA (I don't have SQL Server tools on this computer) but the logic should be right.
[font="Tahoma"]Bryant E. Byrd, BSSE MCDBA MCAD[/font]
Business Intelligence Administrator
MSBI Administration Blog