# How to do same as perl's crypt?

**URL:** <https://www.ruby-forum.com/t/how-to-do-same-as-perls-crypt/194867>\
**Category:** Ruby\
**Created:** [September 12, 2010, 6:15pm UTC](https://www.ruby-forum.com/t/how-to-do-same-as-perls-crypt/194867 "2010-09-12T18:15:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![twtw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@twtw](https://www.ruby-forum.com/u/twtw)\
**Post date:** [September 12, 2010, 6:15pm UTC](https://www.ruby-forum.com/t/how-to-do-same-as-perls-crypt/194867/1 "2010-09-12T18:15:42Z")

</div>

in linux type:  
$ openssl passwd ruby  
get the encrypted string ‘2z8GoTY1O2T3A’, and paste to the followed perl  
script:

# test.pl

$encrypted\_password = “2z8GoTY1O2T3A”;  
$input = $ARGV[0];  
if (crypt($input,$encrypted\_password) eq $encrypted\_password) {  
print “Correct password!\n”;  
}  
else {  
print “Access Denied\n”;  
}

when “perl test.pl ruby”, get  
Correct password!

whe “perl test.pl otherword”, get  
Access Denied

how to compare the input string is in accordance with the encrypted  
string with ruby as same as perl?

---

<div class="post-metadata">

**Author:** ![twtw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@twtw](https://www.ruby-forum.com/u/twtw)\
**Post date:** [September 12, 2010, 8:27pm UTC](https://www.ruby-forum.com/t/how-to-do-same-as-perls-crypt/194867/2 "2010-09-12T20:27:11Z")

</div>

String#crypt
