# perldoc > crypt

---
type: CommandReference
command: crypt
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `crypt($plaintext, $salt)` — one-way hash of a string, typically for password verification
- `crypt($word, $pwd) eq $pwd` — verify a password against a stored digest
- `crypt($plain, $digest) eq $digest` — safe verification using the digest as salt
- `join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]` — generate a random two‑character salt

## Name

`crypt` — one-way hash function for strings, similar to C library `crypt(3)`

## Synopsis

perl
crypt PLAINTEXT, SALT
## Options

- `PLAINTEXT` — the string to hash. Only the first eight bytes matter in traditional DES crypt; modern schemes may use more. If the string is a Unicode string with codepoints above 255, Perl attempts to downgrade a copy to bytes before calling `crypt`; if that fails, `crypt` dies with `Wide character in crypt`.
- `SALT` — a string that determines the hash algorithm and initial conditions. Traditionally two characters from `[./0-9A-Za-z]`; modern systems may accept longer salts (e.g., MD5). When verifying, use the stored digest as the salt. When creating a new salt, generate a random two‑character string from the set `[./0-9A-Za-z]`.

## Examples

perl
my $pwd = (getpwuid($<))[1];

system "stty -echo";
print "Password: ";
chomp(my $word = <STDIN>);
print "\n";
system "stty echo";

if (crypt($word, $pwd) ne $pwd) {
    die "Sorry...\n";
} else {
    print "ok\n";
}
## See Also

- [crypt(3)](http://localhost/phpMan.php/man/crypt/3/markdown) — C library function
- Digest module on CPAN — for robust hashing of large data
- `perlport` — portability notes for `crypt`

## Exit Codes

Not applicable (function returns a string; dies on wide character error).