File: ExampleData.hs

package info (click to toggle)
haskell-yesod-auth-hashdb 1.7.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144 kB
  • sloc: haskell: 689; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 2,774 bytes parent folder | download | duplicates (4)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{-# LANGUAGE OverloadedStrings #-}
module ExampleData (
    OldStyleUser (..),
    NewStyleUser (..),
    mypassword,
    changedpw,
    equivpassword,
    equivchangedpw,
    oldStyleValidUser,
    oldStyleBadUser1,
    oldStyleBadUser2,
    oldStyleUpgradedUser,
    newStyleValidUser,
    newStyleBadUser,
    stronger
) where

import Yesod.Auth.HashDB (HashDBUser(..), defaultStrength)
import Data.Text (Text)

-- OldStyleUser is retained in the tests so that naive (incorrect)
-- upgrading can be tested; the naive upgrade consists of removing
-- the `userPasswordSalt` method without setting new passwords which
-- have empty salt.
data OldStyleUser = OldStyleUser {
                        oldStyleName :: Text,
                        oldStylePass :: Maybe Text,
                        oldStyleSalt :: Maybe Text
                    } deriving (Eq, Show)

instance HashDBUser OldStyleUser where
    userPasswordHash = oldStylePass
    setPasswordHash h u = u { oldStyleSalt = Just "",
                              oldStylePass = Just h
                            }

data NewStyleUser = NewStyleUser {
                        newStyleName :: Text,
                        newStylePass :: Maybe Text
                    } deriving (Eq, Show)

instance HashDBUser NewStyleUser where
    userPasswordHash = newStylePass
    setPasswordHash h u = u { newStylePass = Just h }

mypassword :: Text
mypassword = "mypassword"
changedpw :: Text
changedpw = "changedpw"

-- These are equivalent to the above if each character is truncated to 8 bits
equivpassword :: Text
equivpassword = "\x46d\x479\x470\x461\x473\x473\x477\x46f\x472\x464"
equivchangedpw :: Text
equivchangedpw = "\xbc63\xbc68\xbc61\xbc6e\xbc67\xbc65\xbc64\xbc70\xbc77"

oldStyleValidUser :: OldStyleUser
oldStyleValidUser =
    OldStyleUser "foo"
                 (Just "8e3e33029e71b4e25ba95a00a88c4bfeb93d766a")
                 (Just "somesalt")

oldStyleBadUser1 :: OldStyleUser
oldStyleBadUser1 =
    OldStyleUser "bar"
                 Nothing
                 (Just "pepper")

oldStyleBadUser2 :: OldStyleUser
oldStyleBadUser2 =
    OldStyleUser "baz"
                 (Just "8e3e33029e71b4e25ba95a00a88c4bfeb93d766a")
                 Nothing

oldStyleUpgradedUser :: OldStyleUser
oldStyleUpgradedUser =
    OldStyleUser "foo"
                 (Just "sha256|17|GkImOI0oV9RyOE3oJpYKRg==|KPPYL9JaP6UQjwLVvRsK3Pw2tl1LWyjqlh11jjKRQVM=")
                 (Just "somesalt")

newStyleValidUser :: NewStyleUser
newStyleValidUser =
    NewStyleUser "fox"
                 (Just "sha256|14|2hL7cNopkA/dGy/5CQTuSg==|CUTPW6ICMISSjohFep851f9PdqIn7Y4B75/I77BvEYM=")

newStyleBadUser :: NewStyleUser
newStyleBadUser =
    NewStyleUser "bad"
                 Nothing

stronger :: Int
stronger = defaultStrength + 2