{"id":536,"date":"2010-08-03T20:46:51","date_gmt":"2010-08-04T03:46:51","guid":{"rendered":"http:\/\/chriscarey.com\/wordpress\/?p=536"},"modified":"2011-09-04T15:33:37","modified_gmt":"2011-09-04T22:33:37","slug":"passfail-pl-prevent-password-entry-in-irssi","status":"publish","type":"post","link":"https:\/\/chriscarey.com\/blog\/2010\/08\/03\/passfail-pl-prevent-password-entry-in-irssi\/","title":{"rendered":"passfail.pl &#8211; Prevent password entry in IRSSI"},"content":{"rendered":"<p>Here is a little irssi script that will help prevent you entering your passwords into IRSSI<\/p>\n<p>Click here to download the script: <a href=\"http:\/\/chriscarey.com\/software\/passfail\/passfail.pl\">passfail.pl<\/a><\/p>\n<p>Instructions are inside the file and below:<\/p>\n<p>[perl]<br \/>\nuse strict;<br \/>\nuse Digest::MD5 qw(md5 md5_hex md5_base64);<br \/>\nuse vars qw($VERSION %IRSSI);<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n# passfail.pl &#8211; Help prevent you entering your passwords into IRC by mistake<br \/>\n#<br \/>\n# Copyright (C) 2010 Christopher Carey<br \/>\n# http:\/\/chriscarey.com<br \/>\n#<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n# INSTALL:<br \/>\n#<br \/>\n# Stick the script passfail.pl into your .irssi\/scripts\/ directory.<br \/>\n# Symlink it into the autorun directory so it will run every time the<br \/>\n# application starts.<br \/>\n#<br \/>\n# cp passfail.pl .irssi\/scripts\/<br \/>\n# cd .irssi\/scripts\/<br \/>\n# ln -s passfail.pl autorun\/<br \/>\n#<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n# USAGE:<br \/>\n#<br \/>\n# Passfail has three basic commands: add, remove, show, and clearall.<br \/>\n#<br \/>\n# \/passfail add &lt;password&gt;<br \/>\n#<br \/>\n# The previous command will add the password into the list of protected words.<br \/>\n# That password, if entered in the chat window, will not be sent to channel.<br \/>\n#<br \/>\n# \/passfail remove &lt;password&gt;<br \/>\n#<br \/>\n# The previous command will remove the password from the list of protected words.<br \/>\n# If you type the password, it will be sent to channel.<br \/>\n#<br \/>\n# \/passfail show<br \/>\n#<br \/>\n# The previous command will show the saved password hashes<br \/>\n#<br \/>\n# \/passfail clearall<br \/>\n#<br \/>\n# The previous command will clear the list of protected words (start over).<br \/>\n#<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#<br \/>\n# TESTING:<br \/>\n#<br \/>\n# Test and configure on the (status) window, and not in a channel with users in it!<br \/>\n#<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n#<br \/>\n# OTHER NOTES:<br \/>\n#<br \/>\n# You can manually load or unload the script with the following commands:<br \/>\n#<br \/>\n# \/script load passfail.pl<br \/>\n# \/script unload passfail<br \/>\n#<br \/>\n#<\/p>\n<p>$VERSION = &#8216;20100804&#8217;;<br \/>\n%IRSSI = (<br \/>\n\tauthors\t\t=&gt; &#8216;Chris Carey&#8217;,<br \/>\n\tcontact\t\t=&gt; &#8216;chris@chriscarey.com&#8217;,<br \/>\n\tname\t\t=&gt; &#8216;passfail&#8217;,<br \/>\n\tdescription\t=&gt; &#8216;Prevent your password(s) from going over the wire accidentally&#8217;,<br \/>\n\tlicense\t\t=&gt; &#8216;BSD&#8217;,<br \/>\n\turl\t\t=&gt; &#8216;none&#8217;,<br \/>\n\tmodules\t\t=&gt; &#8216;Digest::MD5&#8217;<br \/>\n);<\/p>\n<p>my @password_md5s;<\/p>\n<p>sub settings_register () {<br \/>\n  # register the irssi settings (with defaults)<br \/>\n  Irssi::settings_add_str(&quot;passfail&quot;, &quot;passfail_hashes&quot;, &quot;&quot;);<br \/>\n}<\/p>\n<p>sub event_send_text () {<\/p>\n<p>  my ($line, $server_rec, $wi_item_rec) = @_;<\/p>\n<p>  # convert the input line to an array of strings<br \/>\n  my @linearray = split(\/ \/, $line);<br \/>\n  my @linearray_md5 = map { md5_hex($_) =&gt; $_ } @linearray;<\/p>\n<p>  # md5_hex each of the linearray elements<br \/>\n  my %linearray_md5 = ();<br \/>\n  map { $linearray_md5{$_} = 1 } @linearray_md5;<\/p>\n<p>  # compare each item in the array against the password hashes<br \/>\n  my @intersection = grep { $linearray_md5{$_} } @password_md5s;<br \/>\n  my $intersection_size = @intersection;<\/p>\n<p>  # compare the input to the array of password hashes<br \/>\n  if ($intersection_size gt 0) {<br \/>\n    # user entered password<br \/>\n\t\tIrssi::print(&quot;passfail.pl blocking password entry&quot;);<br \/>\n  } else {<br \/>\n    # user did not enter password<br \/>\n    return;<br \/>\n  }<br \/>\n\tIrssi::signal_stop();<br \/>\n}<\/p>\n<p>sub display_hashes {<br \/>\n  foreach(@password_md5s) {<br \/>\n    Irssi::print($_);<br \/>\n  }<br \/>\n}<\/p>\n<p>sub settings_load {<br \/>\n  # convert the comma separated hash list into an array<br \/>\n  @password_md5s = split(&#8216;,&#8217;, Irssi::settings_get_str(&#8216;passfail_hashes&#8217;));<br \/>\n  Irssi::print(scalar(@password_md5s).&quot; password(s) loaded&quot;);<br \/>\n}<\/p>\n<p>sub settings_save {<br \/>\n  # convert the array to a comma seperated hash list and store it<br \/>\n  my $hashes = join(&#8216;,&#8217;, @password_md5s);<br \/>\n  Irssi::settings_set_str(&#8216;passfail_hashes&#8217;, $hashes);<br \/>\n  Irssi::print(scalar(@password_md5s).&quot; password(s) saved&quot;);<br \/>\n}<\/p>\n<p>sub cmd_passfail {<br \/>\n  # user typed the command \/passfail<\/p>\n<p>  my $usage = &quot;\/passfail [add|remove|show|clearall] &lt;password&gt;&quot;;<br \/>\n  my ($arguments, $server, $witem) = @_;<br \/>\n  my @foo = split(\/ \/, $arguments);<br \/>\n  my $cmd = @foo[0];<br \/>\n  my $pw = @foo[1];<br \/>\n  my $pw_md5 = md5_hex($pw);<\/p>\n<p>  # sanity check on inputs<br \/>\n  if (!$arguments) {<br \/>\n    Irssi::print($usage);<br \/>\n    return;<br \/>\n  }<br \/>\n  if (length($cmd) eq 0 || length($pw eq 0)) {<br \/>\n    Irssi::print($usage);<br \/>\n    return;<br \/>\n  }<\/p>\n<p>  # switch based on which command was specified<br \/>\n  if ($cmd eq &quot;add&quot;) {<br \/>\n    # add password<br \/>\n    if (grep(\/$pw_md5\/, @password_md5s)) {<br \/>\n      Irssi::print(&quot;Password already exists&quot;);<br \/>\n    } else {<br \/>\n      Irssi::print(&quot;Adding new password&#8230;&quot;);<br \/>\n      push(@password_md5s, $pw_md5);<br \/>\n      &amp;settings_save();<br \/>\n    }<br \/>\n  } elsif ($cmd eq &quot;remove&quot;) {<br \/>\n    # remove password<br \/>\n    Irssi::print(&quot;Removing password&#8230;&quot;);<br \/>\n    @password_md5s = grep { $_ ne $pw_md5 } @password_md5s;<br \/>\n    &amp;settings_save();<\/p>\n<p>  } elsif ($cmd eq &quot;show&quot;) {<br \/>\n    # display hashes<br \/>\n    &amp;display_hashes();<\/p>\n<p>  } elsif ($cmd eq &quot;clearall&quot;) {<br \/>\n    # clear all passwords<br \/>\n    Irssi::print(&quot;Clearing all passwords&#8230;&quot;);<br \/>\n    splice(@password_md5s);<br \/>\n    &amp;settings_save();<\/p>\n<p>  } else {<br \/>\n    # invalid input, show usage<br \/>\n    Irssi::print($usage);<br \/>\n  }<br \/>\n}<\/p>\n<p># program start<br \/>\nsettings_register();<br \/>\nsettings_load();<br \/>\nIrssi::signal_add_first(&#8216;send text&#8217;, &quot;event_send_text&quot;);<br \/>\nIrssi::command_bind(&quot;passfail&quot;, &quot;cmd_passfail&quot;);<\/p>\n<p>[\/perl]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a little irssi script that will help prevent you entering your passwords into IRSSI Click here to download the script: passfail.pl Instructions are inside the file and below: [perl] use strict; use Digest::MD5 qw(md5 md5_hex md5_base64); use vars qw($VERSION %IRSSI); #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; # passfail.pl &#8211; Help prevent you entering your passwords into IRC by [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[10],"tags":[],"class_list":["post-536","post","type-post","status-publish","format-standard","hentry","category-development"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prpYG-8E","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/posts\/536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/comments?post=536"}],"version-history":[{"count":16,"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/posts\/536\/revisions"}],"predecessor-version":[{"id":795,"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/posts\/536\/revisions\/795"}],"wp:attachment":[{"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/media?parent=536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/categories?post=536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chriscarey.com\/blog\/wp-json\/wp\/v2\/tags?post=536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}