password quality is checked in account settings as well

This commit is contained in:
Filip Gralinski 2017-02-18 10:59:27 +01:00
parent 72c358ee62
commit 19b89f26ce
2 changed files with 11 additions and 4 deletions

View File

@ -49,8 +49,8 @@ minPasswordLength :: Int
minPasswordLength = 10 minPasswordLength = 10
isPasswordAcceptable :: Text -> Bool isPasswordAcceptable :: Text -> Bool
isPasswordAcceptable p = length p >= minPasswordLength isPasswordAcceptable p = length p >= minPasswordLength && (p /= "0123456789") && (p /= "1234567890")
tooWeakPasswordMessage :: Handler () tooWeakPasswordMessage :: Handler ()
tooWeakPasswordMessage = tooWeakPasswordMessage =
setMessage $ toHtml ("Password is too weak!!! A password needs to have at least " ++ (show minPasswordLength) ++ " characters") setMessage $ toHtml ("Password is too weak!!! A password needs to have at least " ++ (show minPasswordLength) ++ " characters.")

View File

@ -9,7 +9,7 @@ import Data.Conduit.Binary
import qualified Data.ByteString as S import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy as L
import Handler.Common (passwordConfirmField, updatePassword) import Handler.Common (passwordConfirmField, updatePassword, isPasswordAcceptable, tooWeakPasswordMessage)
getYourAccountR :: Handler Html getYourAccountR :: Handler Html
getYourAccountR = do getYourAccountR = do
@ -32,13 +32,20 @@ postYourAccountR = do
_ -> Nothing _ -> Nothing
case accountData of case accountData of
Just (name, localId, mPassword, sshPubKey, avatarFile) -> do Just (name, localId, mPassword, sshPubKey, avatarFile) -> do
if checkPassword mPassword
then
updateUserAccount userId name localId mPassword sshPubKey avatarFile updateUserAccount userId name localId mPassword sshPubKey avatarFile
else
tooWeakPasswordMessage
Nothing -> do Nothing -> do
setMessage $ toHtml ("Something went wrong, probably the password did not match" :: Text) setMessage $ toHtml ("Something went wrong, probably the password did not match" :: Text)
defaultLayout $ do defaultLayout $ do
setTitle "Your account" setTitle "Your account"
$(widgetFile "your-account") $(widgetFile "your-account")
checkPassword :: Maybe Text -> Bool
checkPassword (Just passwd) = isPasswordAcceptable passwd
checkPassword Nothing = False
yourAccountForm :: Maybe Text -> Maybe Text -> Maybe Text -> Form (Maybe Text, Maybe Text, Maybe Text, Maybe Text, Maybe FileInfo) yourAccountForm :: Maybe Text -> Maybe Text -> Maybe Text -> Form (Maybe Text, Maybe Text, Maybe Text, Maybe Text, Maybe FileInfo)
yourAccountForm maybeName maybeLocalId maybeSshPubKey = renderBootstrap3 BootstrapBasicForm $ (,,,,) yourAccountForm maybeName maybeLocalId maybeSshPubKey = renderBootstrap3 BootstrapBasicForm $ (,,,,)