Skip to content

passlib.hash.mssql2000 - MS SQL 2000 password hash

Danger

This algorithm is not considered secure by modern standards. It should only be used when verifying existing hashes, or when interacting with applications that require this format. For new code, see the list of recommended hashes.

This class implements the hash algorithm used by Microsoft SQL Server 2000 to store its user account passwords, until it was replaced by a slightly more secure variant (mssql2005) in MSSQL 2005. This class can be used directly as follows:

from passlib.hash import mssql2000 as m20

# hash password
h = m20.hash("password")
print(h)
# > '0x0100200420C4988140FD3920894C3EDC188E94F428D57DAD5905F6CC1CBAF950CAD4C63F272B2C91E4DEEB5E6444'

# verify correct password
print(m20.verify("password", h))
# > True
print(m20.verify("letmein", h))
# > False

Tip

  • See the PasswordHash usage examples for more usage details.
  • mssql2005 -- the successor to this hash.

Interface

mssql2000

mssql2000(salt=None, **kwds)

This class implements the password hash used by MS-SQL 2000, and follows the :ref:password-hash-api.

It supports a fixed-length salt.

The :meth:~passlib.ifc.PasswordHash.using method accepts the following optional keywords:

Parameters:

  • salt (bytes, default: None ) –

    Optional salt string. If not specified, one will be autogenerated (this is recommended). If specified, it must be 4 bytes in length.

  • relaxed (bool) –

    By default, providing an invalid value for one of the other keywords will result in a :exc:ValueError. If relaxed=True, and the error can be corrected, a :exc:~passlib.exc.PasslibHashWarning will be issued instead. Correctable errors include salt strings that are too long.

encrypt classmethod

encrypt(*args, **kwds)

Legacy alias for :meth:hash.

.. deprecated:: 1.7 This method was renamed to :meth:!hash in version 1.7. This alias will be removed in version 2.0, and should only be used for compatibility with Passlib 1.3 - 1.6.

parsehash classmethod

parsehash(hash, checksum=True, sanitize=False)

[experimental method] parse hash into dictionary of settings.

this essentially acts as the inverse of :meth:hash: for most cases, if hash = cls.hash(secret, **opts), then cls.parsehash(hash) will return a dict matching the original options (with the extra keyword checksum).

this method may not work correctly for all hashes, and may not be available on some few. its interface may change in future releases, if it's kept around at all.

Parameters:

  • hash –

    hash to parse

  • checksum –

    include checksum keyword? (defaults to True)

  • sanitize –

    mask data for sensitive fields? (defaults to False)

bitsize classmethod

bitsize(salt_size=None, **kwds)

[experimental method] return info about bitsizes of hash

default_salt_size

default_salt_size()

default salt size (defaults to max_salt_size)

default_salt_chars

default_salt_chars()

charset used to generate new salt strings (defaults to salt_chars)

Format & Algorithm

MSSQL 2000 hashes are usually presented as a series of 92 upper-case hexadecimal characters, prefixed by 0x. An example MSSQL 2000 hash (of "password"):

0x0100200420C4988140FD3920894C3EDC188E94F428D57DAD5905F6CC1CBAF950CAD4C63F272B2C91E4DEEB5E6444

This encodes 46 bytes of raw data, consisting of:

  • a 2-byte constant 0100
  • 4 byte of salt (200420C4 in the example)
  • the first 20 byte digest (988140FD3920894C3EDC188E94F428D57DAD5905 in the example).
  • a second 20 byte digest (F6CC1CBAF950CAD4C63F272B2C91E4DEEB5E6444 in the example).

The first digest is generated by encoding the unicode password using UTF-16-LE, and calculating SHA1(encoded_secret + salt).

The second digest is generated the same as the first, except that the password is converted to upper-case first.

Only the second digest is used when verifying passwords (and hence the hash is case-insensitive). The first digest is presumably for forward-compatibility: MSSQL 2005 removed the second digest, and thus became case sensitive.

Note

MSSQL 2000 hashes do not actually have a native textual format, as they are stored as raw bytes in an SQL table. However, when external programs deal with them, MSSQL generally encodes raw bytes as upper-case hexadecimal, prefixed with 0x. This is the representation Passlib uses.

Security Issues

This algorithm is reasonably weak, and shouldn't be used for any purpose besides manipulating existing MSSQL 2000 hashes, due to the following flaws:

  • The fact that it is case insensitive greatly reduces the keyspace that must be searched by brute-force or pre-computed attacks. 1

  • Its simplicity, and years of research on high-speed SHA1 implementations, makes efficient brute force attacks much more feasible. 2