Name

crypt — encrypt a string exactly like the crypt(3) function in the C library

ATTRIBUTES

Attribute Pos. Req. Default Description
value | password Yes Yes   Text to encrypt.
salt | crypted Yes   Random 2-character string Crypt salt. You usually want to leave it empty for the tag to generate the random salt itself. Specifying salt only makes sense for testing purposes, or when you're verifying the password, like you see in the section called “EXAMPLES”.
interpolate     0 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

Encrypts a string exactly like the crypt(3) function in the C library.

Note that crypt is intended to be a one-way function, much like breaking eggs to make an omelette. There is no (known) corresponding decrypt function. As a result, this function isn't all that useful for any cryptography.

This tag simply calls the Perl built-in crypt() function.

When verifying an existing encrypted string you should use the encrypted text as the salt (like [crypt PLAIN CRYPTED]) and compare that to CRYPTED (it should be equal). This allows your code to work with the standard crypt and with more exotic implementations.

When choosing a new salt, either let the tag generate a 2-character random string itself, or generate one yourself from the [./0-9A-Za-z] set. (working Perl code would be join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64].

The crypt function is unsuitable for encrypting large quantities of data, not least of all because you can't get the information back.

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

Example: Crypt a string and verify it

Note that this example is of little use in practice, but does show the components you can re-use:
<p>
[seti salt][perl]join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64][/perl][/seti]
String "test" crypted with salt "[scratch salt]": [crypt value="test" salt="[scratch salt]"]
</p>

<p>
[seti crypted][crypt value="test" salt="[scratch salt]"][/seti]
Checking validity: [crypt value="test" salt="[scratch crypted]"]
</p>

<p>
[perl]
$Tag->crypt("test", $Scratch->{crypted}) eq $Scratch->{crypted} ?
  "Password matches." : "Password does not match."
[/perl]
</p>

NOTES

AVAILABILITY

crypt is available in Interchange versions:

4.8.0-5.7.0 (cvs-head)

SOURCE

Interchange 5.7.0:

Source: code/UI_Tag/crypt.coretag
Lines: 19


# Copyright 2003-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: crypt.coretag,v 1.6 2007/03/30 23:40:54 pajamian Exp $

UserTag crypt Order     value salt
UserTag crypt attrAlias password value
UserTag crypt attrAlias crypted salt
UserTag crypt Version   $Revision: 1.6 $
UserTag crypt Routine   <<EOR
sub {
my ($string, $salt) = @_;
return crypt($string, $salt ? $salt : Vend::Util::random_string(2))
}
EOR

AUTHORS

Interchange Development Group

SEE ALSO

Password(7ic)

DocBook! Interchange!