File: Password.pm

package info (click to toggle)
perlmoo 0.045
  • links: PTS
  • area: main
  • in suites: slink
  • size: 404 kB
  • ctags: 242
  • sloc: perl: 5,211; makefile: 111; sh: 77
file content (29 lines) | stat: -rw-r--r-- 561 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Password setting and checking library.

package Password;

# Returns a crypted password
sub encrypt {
	my $password=shift;
	
	my @valid = map (chr,((ord('.')..ord('9')),(ord('A')..ord('Z')),(ord('a')..ord('z'))));
	my $salt = $valid[rand($#valid+1)].$valid[rand($#valid+1)];
	
	return crypt($password,$salt)
}

# Pass it a plaintext password and a crypted one, returns true
# if the plaintext password is ok.
sub check {
	my $plaintext=shift;
	my $crypted=shift;

	if (crypt($plaintext, $crypted) eq $crypted) {
		return 1;
	}
	else {
		return undef;
	}
}

1