File: Crypt.hs

package info (click to toggle)
haskell-unixutils 1.52-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 112 kB
  • sloc: haskell: 494; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (5)
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
{-# LANGUAGE ForeignFunctionInterface #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  System.Unix.Crypt
-- Copyright   :  (c) 2010
-- License     :  BSD3
-- 
-- Maintainer  :  jeremy@seereason.com
-- Stability   :  provisional
-- Portability :  non-portable (requires POSIX)
--
-- support for crypt() and /etc/shadow
--
-----------------------------------------------------------------------------

module System.Unix.Crypt 
    ( crypt
    )
    where

import Foreign.C

foreign import ccall unsafe "unistd.h crypt"
  c_crypt :: CString -> CString -> IO CString

-- | calls crypt(3) 
crypt :: String -- ^ key
      -> String -- ^ salt
      -> IO String -- ^ encrypted password
crypt key salt =
    withCString key $ \ckey ->
        withCString salt $ \csalt ->
            do cpassword <- throwErrnoIfNull "crypt" (c_crypt ckey csalt)
               peekCString cpassword