0

I have a column in MSSQL which is nvarchar(50) in which I enter passwords for users. I know that for example some special characters like $ % are allowed, but where do I see which list characters are allowed?

2 Answers 2

1

nchar/nvarchar are SQL Server's fixed and flexible length UNICODE UCS-2 character set data types.

The question then becomes, what the heck is UCS-2? And according to wikipedia, it's going to allow for 1.1M code points.

The following has been copied from the wiki article as I'm a dumb 'merican and I've tapped out of understanding what this all means.

Code points U+0000 to U+D7FF and U+E000 to U+FFFF

The first plane (code points U+0000 to U+FFFF) contains the most frequently used characters and is called the Basic Multilingual Plane or BMP. Both UTF-16 and UCS-2 encode code points in this range as single 16-bit code units that are numerically equal to the corresponding code points. The code points in the BMP are the only code points that can be represented in UCS-2. Within this plane, code points U+D800 to U+DFFF (see below) are reserved for lead and trail surrogates.

Code points U+10000 to U+10FFFF

Code points from the other planes (called Supplementary Planes) are encoded in UTF-16 by pairs of 16-bit code units called surrogate pairs, by the following scheme:

  • 0x010000 is subtracted from the code point, leaving a 20 bit number in the range 0..0x0FFFFF.
  • The top ten bits (a number in the range 0..0x03FF) are added to 0xD800 to give the first code unit or lead surrogate, which will be in the range 0xD800..0xDBFF. (Previous versions of the Unicode Standard referred to these as high surrogates.)
  • The low ten bits (also in the range 0..0x03FF) are added to 0xDC00 to give the second code unit or trail surrogate, which will be in the range 0xDC00..0xDFFF. (Previous versions of the Unicode Standard referred to these as low surrogates.)

Since the ranges for the lead surrogates, trail surrogates, and valid BMP characters are disjoint, searches are simplified: it is not possible for part of one character to match a different part of another character. It also means that UTF-16 is self-synchronizing on 16-bit words: whether a code unit starts a character can be determined without examining earlier code units. UTF-8 shares these advantages, but many earlier multi-byte encoding schemes did not allow unambiguous searching and could only be synchronized by re-parsing from the start of the string. UTF-16 is not self-synchronizing if one byte is lost or if traversal starts at a random byte.

Because the most commonly used characters are all in the Basic Multilingual Plane, handling of surrogate pairs is often not thoroughly tested. This leads to persistent bugs and potential security holes, even in popular and well-reviewed application software (e.g. CVE-2008-2938, CVE-2012-2135)

1

NVARCHAR can have Unicode characters. http://msdn.microsoft.com/en-us/library/ms186939.aspx

Prefix Unicode character string constants with the letter N. Without the N prefix, the string is converted to the default code page of the database. This default code page may not recognize certain characters.

DECLARE @nv NVARCHAR(20)
SET @nv = N'Minyā'
SELECT @nv

Here is the list of Unicode Characters: http://en.wikipedia.org/wiki/List_of_Unicode_characters

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .