cdepillabout / cdepillabout/password
Documentation addition for working with JSON
- Dominant language
- Haskell
- Stars
- 61
- Forks
- 16
- PR merge metrics
- No merged PRs in 30d
Description
After talking to someone who used `password-instances`, it's still somewhat annoying to have to make a field `Text`, just because you want to also use it with `ToJSON` to send between services.
It might be a good idea to give an example to make this more convenient, because they did say they think it's a good idea not to allow `Password` to be turned into JSON for security's sake.
I think something in the documentation near the JSON instances like the following would make it easier for users to switch between `Text` and `Password` within other types:
Instead of:
```hs
data LoginForm = LoginForm
{ loginUsername :: UserName
, loginPassword :: Text
}
```
and then changing the `loginPassword` to `Password` just before hashing or checking, do the following:
```hs
data LoginForm a = LoginForm
{ loginUserName :: UserName
, loginPassword :: a
} deriving (Show, Functor)
```
This way, you can have a `ToJSON` instance for `LoginForm` while still using `LoginForm Password` everywhere in your code, while just doing:
```hs
unsafeShowPassword <$> loginForm :: LoginForm Text
```
just before sending it over the wire, and you can still just get the password straight from JSON because of the `FromJSON` instance.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.