Add a way to save password no really clear
This commit is contained in:
parent
5709fa03d2
commit
4cb9831d49
55
ACU/Password.pm
Normal file
55
ACU/Password.pm
Normal file
@ -0,0 +1,55 @@
|
||||
#! /usr/bin/env perl
|
||||
|
||||
package Password;
|
||||
|
||||
use v5.10.1;
|
||||
use strict;
|
||||
use warnings;
|
||||
use MIME::Base64 qw(encode_base64 decode_base64);
|
||||
|
||||
our $hostname = `hostname`;
|
||||
chomp($hostname);
|
||||
|
||||
sub cxor($$)
|
||||
{
|
||||
my $msg = shift;
|
||||
my $key = shift;
|
||||
my $xor = "";
|
||||
my $lk = length($key);
|
||||
my $lm = length($msg);
|
||||
|
||||
for (my $i = 0; $i < $lm; $i++) {
|
||||
$xor .= substr($msg, $i, 1) ^ substr($key, $i % $lk, 1);
|
||||
}
|
||||
|
||||
return $xor;
|
||||
}
|
||||
|
||||
sub gen_password(;$$)
|
||||
{
|
||||
my $file = shift // ".secret_intra";
|
||||
my $pass = shift // `pwgen -s -n -c -y -1 42 1`;
|
||||
chomp($pass);
|
||||
|
||||
open SECRET, ">", $file;
|
||||
print SECRET encode_base64(cxor($pass, $hostname));
|
||||
close SECRET;
|
||||
|
||||
return $pass;
|
||||
}
|
||||
|
||||
sub get_password(;$)
|
||||
{
|
||||
my $file = shift // ".secret_intra";
|
||||
|
||||
my $decode = "";
|
||||
open SECRET, "<", $file;
|
||||
while (<SECRET>) {
|
||||
$decode .= $_;
|
||||
}
|
||||
close SECRET;
|
||||
|
||||
return cxor(decode_base64($decode), $hostname);
|
||||
}
|
||||
|
||||
1;
|
Reference in New Issue
Block a user