Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Created September 23, 2019 14:52
Show Gist options
  • Save ninjarobot/32421ef5976842d907fa8ada0ee34456 to your computer and use it in GitHub Desktop.
Save ninjarobot/32421ef5976842d907fa8ada0ee34456 to your computer and use it in GitHub Desktop.
Using cracklib from F#
open System
open System.Runtime.InteropServices
[<DllImport("libcrack.so.2", CallingConvention=CallingConvention.Cdecl)>]
extern nativeint FascistCheck(string pw, string dictPath)
[<EntryPoint>]
let main argv =
while true do
Console.WriteLine "Enter a potential password:"
let input = Console.ReadLine ()
try
let res = FascistCheck(input, "/var/cache/cracklib/cracklib_dict")
let s = Marshal.PtrToStringAnsi res
if String.IsNullOrEmpty s then
Console.WriteLine "Acceptable"
else
Console.WriteLine s
with
| :? DllNotFoundException ->
Console.Error.WriteLine "libcrack not installed."
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment