Click here to Skip to main content
15,892,797 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hello guys,

please suggest sql query for input password whcich does not contatin consecutuive reprating chrcters
Posted

Why would you want to use an SQL query to do this?
That would mean passing a human readable text string password to SQL, which is a security risk as well as silly - passwords should be hashed well before they get to SQL: Password Storage: How to do it.[^]

And besides, why should two consecutive characters not be the same: I frequently use GUID values as passwords, and they do contain repeating characters - which does not reduce the security level in the slightest!

Do validation in your presentation software, and only send valid (secure) data to SQL.
 
Share this answer
 
Comments
rajshreelande 21-Oct-14 3:09am    
becoz its a requriment do validations from database..
Have a look at example:
SQL
DECLARE @string VARCHAR(30) = 'rahkkkff'

;WITH CTE AS
(
	SELECT 1 AS LetterPosition, CONVERT(VARCHAR(1),LEFT(@string, 1)) AS Letter, RIGHT(@string,LEN(@string)-1) AS Remainder, CHARINDEX(REPLICATE(LEFT(@string, 1),3), @string, 1) AS FoundedAt
	WHERE LEN(@string)>1
	UNION ALL
	SELECT LetterPosition + 1 AS LetterPosition, CONVERT(VARCHAR(1),LEFT(Remainder, 1)) AS Letter, RIGHT(Remainder,LEN(Remainder)-1) AS Remainder, CHARINDEX(REPLICATE(LEFT(Remainder, 1),3), Remainder, 1) AS FoundedAt
	FROM CTE
	WHERE LEN(Remainder)>1
	UNION ALL
	SELECT LetterPosition +1 AS LetterPosition, CONVERT(VARCHAR(1),Remainder) AS Letter, NULL AS Remainder, CHARINDEX(REPLICATE(LEFT(Remainder, 1),3), Remainder, 1) AS FoundedAt
	FROM CTE
	WHERE LEN(Remainder)=1
)
SELECT @string AS MyString, REPLICATE(Letter,3) AS ConsecutiveLetters, LetterPosition AS FoundedAt
FROM CTE
WHERE FoundedAt=1


Result:
rahkkkff	kkk	4


Above query is used to check string for 3 consecutive letters, BUT...
You wrote: "query for input password whcich does not contatin consecutuive reprating chrcters", which means that you store passwords as a plain text. It's BAD idea!
Please, see:
http://stackoverflow.com/questions/1054022/best-way-to-store-password-in-database[^]
Beginners guide to a secure way of storing passwords[^]
 
Share this answer
 
Comments
rajshreelande 22-Oct-14 3:53am    
thanks it working but its a genric slution i want to make it dyanamic means different client having differnt requriment if suppse one client restrict 4 consecutive letter and another restrict 2 consecutive letter in that case how to do it..

please help me
thanks in advance..
Maciej Los 22-Oct-14 6:35am    
See the MSDN documentation for REPLICATE(LEFT(@string, 1),3) function.
Maciej Los 22-Oct-14 6:44am    
If this answer meets your needs, please, accept my answer as a solution (green button).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900