Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main exposing (Issue, Model, Msg(..), PasswdFeedback, init, inp, main, update, validate, view)
- import Browser
- import Html exposing (Html, div, input, pre, text)
- import Html.Attributes exposing (disabled, placeholder, style, type_, value)
- import Html.Events exposing (onInput)
- import Set
- main =
- Browser.sandbox { init = init, update = update, view = view }
- type alias Model =
- { name : String
- , pass : String
- , pass2 : String
- , fdbk : PasswdFeedback
- }
- type alias PasswdFeedback =
- { locked : Bool
- , narration : List String
- }
- type alias Issue =
- { hide : Bool
- , explaination : String
- }
- init : Model
- init =
- Model "" "" "" (PasswdFeedback True [])
- type Msg
- = DelName String
- | DelPass String
- | DelPass2 String
- view model =
- div []
- [ inp "text" "Name" model.name DelName False
- , inp "password" "Password" model.pass DelPass False
- , inp "password" "Password2" model.pass2 DelPass2 model.fdbk.locked
- , pre [ style "color" "red" ] [ text (String.join "\n" model.fdbk.narration) ]
- ]
- update msg model =
- case msg of
- DelName x ->
- { model | name = x }
- DelPass x ->
- { model | pass = x, fdbk = validate x }
- DelPass2 x ->
- { model | pass2 = x }
- inp : String -> String -> String -> (String -> msg) -> Bool -> Html msg
- inp t ph val signal q =
- input [ type_ t, placeholder ph, value val, onInput signal, disabled q ] []
- validate : String -> PasswdFeedback
- validate passwd =
- let
- isCaps c =
- String.contains (String.fromChar c) "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- isLower c =
- String.contains (String.fromChar c) "abcdefghijklmnopqrstuvwxyz"
- isPunct c =
- String.contains (String.fromChar c) "~!@#$%^&*()-_=+[]{}'\\;:,./<>?|"
- isDigit c =
- Maybe.withDefault -1 (String.toInt (String.fromChar c)) >= 0
- -- isDigit : Char -> Bool
- nonZero =
- String.length passwd > 0
- lenOk =
- Issue (String.length passwd > 7) "Password too small."
- hasDigit =
- Issue (String.any isDigit passwd) "No digits."
- hasCapital =
- Issue (String.any isCaps passwd) "No capitals."
- hasLower =
- Issue (String.any isLower passwd) "No lower case."
- hasPunct =
- Issue (String.any isPunct passwd) "No punctuation."
- worthShowing issue =
- if issue.hide == False then
- Just issue.explaination
- else
- Nothing
- goodPass =
- List.all .hide [ lenOk, hasDigit, hasCapital, hasLower, hasPunct ]
- in
- if nonZero && goodPass then
- PasswdFeedback False []
- -- else if ...the 32 cases
- else
- PasswdFeedback True
- (List.filterMap worthShowing [ lenOk, hasDigit, hasCapital, hasLower, hasPunct ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement