iLTC Home
Bookmark iLTC!

Categories

Perl
  • Perl Tutorials Beginners

  • Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

  • HTML
  • HTML Tutorials

  • Command Line
  • Command Line Tutorials

  • How Tos
  • Other Tips and Tricks



  • #!/usr/bin/perl
    2210855

    iLoveTheCode.com

    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





    Previous Article: To Reverse an Array in Perl
    Next Article: And, Or, Equal, Not Equal, Greater Than, Less Than in Perl






    Search iLTC w/ Google




    Recent Articles

  • HTML Font Code
  • Javascript and CSS - Easy Pop Up Help Balloons
  • Use OnMouseOver in Javascript
  • Use onMouseOut in Javascript
  • Use innerHTML to Change Text on a Page
  • Renaming a File with Perl's RENAME Function
  • PRINT to Browser with document.write Command in Javascript
  • Passing an Argument or Variable to a Javascript
  • Opening an Alert Box in Javascript
  • Opening a REMOTE WINDOW in Javascript
  • OPEN and WRITE a Data File in Perl
  • OPEN and READ a Data File in Perl
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Javascript Reset Form








  • Perl Programming - Javascript Programming - HTML Code - Mac Unix Command Line - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006-2009 iLoveTheCode.com


    Contact Chris | About this Site


    2210066
    Counter by iLoveTheCode.com


    Last Modified: Saturday, 10-Jan-2009 05:40:24 EST



    Hosted as well :)
    Home-brewed logo - 1997