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