iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • I bookmarked this site...
    123,773

    iLoveTheCode.com
    Perl > Perl Tutorials How To Easy > Encryption with the Crypt Function in Perl

    Encryption with the Crypt Function in Perl



    To encrypt with the crypt function in Perl:

    $ji="12Fr7";

    $ji=crypt($ji,"AP");

    print "$ji";


    -We created a variable ji and stored a password there.
    -We called the built-in crypt function.
    -Inside the parenthesis, we first state what is to be crypted ($ji)
    -The second part in the parenthesis, after the comma, is the salt which consists of any 2 letters or numbers.
    -We print the results.

    NOTE: There is no decrypt. The crypt function is used for checking crypted input against crypted stored...

    In other words:
    -a user types their password in a form
    -you crypt it
    -you check it against their previously stored crypted password


    Another example that makes for more varied encryption:

    $ji="12Fr7";

    $ssalt=$ji;
    $ji=crypt($ji,$ssalt);

    print "$ji";


    -Again, we created $ji.
    -We stored $ji into a variable named $ssalt
    -We used our new $ssalt variable to crypt $ji
    -Essentially, we used $ji to crypt $ji, but that might be confusing to look at, codewise :)

    IN CASE YOU'RE WONDERING: Although our new variable $ssalt is five characters long, the crypt function uses only the first two letters when making the salt. *


    * Thanks to Randal L. Schwartz for correcting me about this on the iLTC Google Group.


    Copy and Paste Perl Code:

    #!/usr/bin/perl

    print "Content-type:text/html\n\n";

    $ji="12Fr7";
    $ji=crypt($ji,"12");
    print "$ji<br>";


    $ji="12Fr7";
    $ssalt=$ji;
    $ji=crypt($ji,$ssalt);
    print "$ji<br>";


    $ji="12Fr7";
    $ji=crypt($ji,$ji);
    print "$ji";


    exit;


    Resources:
    Substitute in Perl
    Matching with a Regular Expression, REGEX, in Perl
    Getting What is Matched in Perl
    Matching at the Beginning and End
    Matching at the Beginning and End 2



    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: To Reverse an Array in Perl
    Next Article: And, Or, Equal, Not Equal, Greater Than, Less Than in Perl





    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $23.99

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    jQuery in ActionjQuery in Action

    Bear Bibeault, Yeh...

    New $26.39

    JavaScriptJavaScript

    David Flanagan

    New $31.49

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09

    CSSCSS

    David McFarland

    New $23.09

    CSSCSS

    Eric Meyer

    New $29.69

    Information Architecture...Information Architecture for the Wor...

    Louis Rosenfeld, P...

    New $26.39


    Of Interest:
  • Use chmod in Perl
  • To Reverse an Array in Perl
  • What's in an Array, Index Numbers
  • Making a Directory Using mkdir in Perl
  • Javascript Uppercase Text
  • Environmental Variables Available in Javascript using Navigator Object
  • Javascript Reverse - Use Reverse on Items in an Array in Javascript
  • Opening a REMOTE WINDOW in Javascript
  • Make Italic Text Using HTML
  • HTML Space
  • HTML Tags
  • HTML Frames

  • More Articles:
  • To See if a Directory Exists in Perl
  • Finding the Length (Index Numbers) of an Array in Perl
  • Putting Two Strings Together, Concatenate
  • Create a Subroutine in Perl
  • onClick Javascript
  • Get Query String Using Javascript
  • If, Else If, and Else in Javascript
  • Get String Length with Javascript
  • Use onMouseOut in Javascript
  • HTML Superscript Text
  • HTML Body Tag
  • Make Text Bold Using HTML
  • HTML Title Tag

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    420,534
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:13 EDT