blob: 429da265606224f4fd5c631bc79fbcf5807a89b2 (
plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
module m_crypt
implicit none
contains
function hash(phrase)
use utilities, only: get_one_line_output_shell_command
implicit none
character(len=*), intent(in)::phrase
character(len=:), pointer::hash
character(len=256)::tempout
call get_one_line_output_shell_command('mkpasswd -m sha-512 "'//trim(phrase)//'"', &
tempout)
allocate(character(len=len_trim(tempout)) :: hash)
hash = trim(tempout)
end function hash
function verify_hash(phrase, hashed)
use utilities, only: get_one_line_output_shell_command
implicit none
character(len=*), intent(in)::phrase, hashed
logical::verify_hash
character(len=256)::tempout
character(32)::salt
integer::i
i = index(hashed(4:len_trim(hashed)), "$")
salt = hashed(4:i+2)
call get_one_line_output_shell_command('mkpasswd -m sha-512 -S '//trim(salt)//' "'//trim(phrase)//'"', &
tempout)
verify_hash = (trim(tempout) == trim(hashed))
end function verify_hash
end module m_crypt
|