anchor.diff:  maybe_value(Key, Else, Fun) ->
       [{Key, Fun(Else)}].
   
  +maybe_upgrade_password_hash(UserName, Password, UserProps) ->
  +    case couch_util:get_value(<<"password_scheme">>, UserProps, <<"simple">>) of
  +    <<"simple">> ->
  +        DbName = ?l2b(config:get("couch_httpd_auth", "authentication_db", "_users")),
  +        couch_util:with_db(DbName, fun(UserDb) ->
  +            UserProps2 = proplists:delete(<<"password_sha">>, UserProps),
  +            UserProps3 = [{<<"password">>, Password} | UserProps2],
  +            NewUserDoc = couch_doc:from_json_obj({UserProps3}),
  +            {ok, _NewRev} = couch_db:update_doc(UserDb, NewUserDoc, []),
  +            couch_auth_cache:get_user_creds(UserName)
  +        end);
  +    _ ->
  +        UserProps
  +    end.
  +
   authenticate(Pass, UserProps) ->
       UserSalt = couch_util:get_value(<<"salt">>, UserProps, <<>>),
       {PasswordHash, ExpectedHash} =
  
positive.code:             send_json(Req#httpd{req_body=ReqBody}, Code, Headers,
                  {[
                      {ok, true},
                      {name, couch_util:get_value(<<"name">>, User, null)},
                      {roles, couch_util:get_value(<<"roles">>, User, [])}
                  ]});
          _Else ->
              % clear the session
  
negative.code:             nil ->
                  throw({unauthorized, <<"Name or password is incorrect.">>});
              UserProps ->
                  UserName = ?l2b(User),
                  Password = ?l2b(Pass),
                  case authenticate(Password, UserProps) of
                      true ->
                          UserProps2 = maybe_upgrade_password_hash(UserName, Password, UserProps),
                          Req#httpd{user_ctx=#user_ctx{
                              name=UserName,
                              roles=couch_util:get_value(<<"roles">>, UserProps2, [])
                          }};
                      _Else ->
                          throw({unauthorized, <<"Name or password is incorrect.">>})
  