aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--captain/cryptcl.f9044
1 files changed, 44 insertions, 0 deletions
diff --git a/captain/cryptcl.f90 b/captain/cryptcl.f90
new file mode 100644
index 0000000..429da26
--- /dev/null
+++ b/captain/cryptcl.f90
@@ -0,0 +1,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 \ No newline at end of file