MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / crypt

Function crypt

thirdparty/fcrypt/fcrypt.py:547–609  ·  view source on GitHub ↗

Generate an encrypted hash from the passed password. If the password is longer than eight characters, only the first eight will be used. The first two characters of the salt are used to modify the encryption algorithm used to generate in the hash in one of 4096 different ways. The characters for t

(password, salt)

Source from the content-addressed store, hash-verified

545
546
547def crypt(password, salt):
548 """Generate an encrypted hash from the passed password. If the password
549is longer than eight characters, only the first eight will be used.
550
551The first two characters of the salt are used to modify the encryption
552algorithm used to generate in the hash in one of 4096 different ways.
553The characters for the salt should be upper- and lower-case letters A
554to Z, digits 0 to 9, '.' and '/'.
555
556The returned hash begins with the two characters of the salt, and
557should be passed as the salt to verify the password.
558
559Example:
560
561 >>> from fcrypt import crypt
562 >>> password = 'AlOtBsOl'
563 >>> salt = 'cE'
564 >>> hash = crypt(password, salt)
565 >>> hash
566 'cEpWz5IUCShqM'
567 >>> crypt(password, hash) == hash
568 1
569 >>> crypt('IaLaIoK', hash) == hash
570 0
571
572In practice, you would read the password using something like the
573getpass module, and generate the salt randomly:
574
575 >>> import random, string
576 >>> saltchars = string.ascii_letters + string.digits + './'
577 >>> salt = random.choice(saltchars) + random.choice(saltchars)
578
579Note that other ASCII characters are accepted in the salt, but the
580results may not be the same as other versions of crypt. In
581particular, '_', '$1' and '$2' do not select alternative hash
582algorithms such as the extended passwords, MD5 crypt and Blowfish
583crypt supported by the OpenBSD C library.
584"""
585
586 # Extract the salt.
587 if len(salt) == 0:
588 salt = 'AA'
589 elif len(salt) == 1:
590 salt = salt + 'A'
591 Eswap0 = _con_salt[ord(salt[0]) & 0x7f]
592 Eswap1 = _con_salt[ord(salt[1]) & 0x7f] << 4
593
594 # Generate the key and use it to apply the encryption.
595 ks = _set_key((password + '\0\0\0\0\0\0\0\0')[:8])
596 o1, o2 = _body(ks, Eswap0, Eswap1)
597
598 # Extract 24-bit subsets of result with bytes reversed.
599 t1 = (o1 << 16 & 0xff0000) | (o1 & 0xff00) | (o1 >> 16 & 0xff)
600 t2 = (o1 >> 8 & 0xff0000) | (o2 << 8 & 0xff00) | (o2 >> 8 & 0xff)
601 t3 = (o2 & 0xff0000) | (o2 >> 16 & 0xff00)
602 # Extract 6-bit subsets.
603 r = [ t1 >> 18 & 0x3f, t1 >> 12 & 0x3f, t1 >> 6 & 0x3f, t1 & 0x3f,
604 t2 >> 18 & 0x3f, t2 >> 12 & 0x3f, t2 >> 6 & 0x3f, t2 & 0x3f,

Callers 1

crypt_generic_passwdFunction · 0.90

Calls 3

_set_keyFunction · 0.85
_bodyFunction · 0.85
xrangeClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…