donglankui1263 2017-08-14 01:22
浏览 96
已采纳

更改基本HTTP身份验证领域和登录对话框消息

I want to change the message that pops up during implementation of Basic Auth.The current default message is:

enter image description here

Server requires a username and password.

Something that would be more accurate for me is :

Server requires an Email and Password.

My problem is that i can't find or don't know where this message is set and if it can be changed. Most of the questions online are about Basic Auth implemention but this is not my problem -- i can implement it very fine. I just need a more accurate response for the user.

Here is how i force an authentication window using echo:

c.Response().Header().Set(echo.HeaderWWWAuthenticate, `Basic realm="Your Email is your Username"`)
return echo.ErrUnauthorized

NB: Only Firefox shows the realm message. Both Chrome and Opera do not.

  • 写回答

2条回答 默认 最新

  • doufangpian5545 2017-08-17 02:46
    关注

    Thanks for the responses but they were not satisfactory. I had to do some reading on this topic.

    The correct answer is that the login prompt/dialog is a response built into the user-agent/browser and cannot be changed by the server. This also explains why some browsers show realm while others don't.

    According to Wikipedia Basic access authentication all the server does is:

    When the server wants the user agent to authenticate itself towards the server, it must respond appropriately to unauthenticated requests.

    Unauthenticated requests should return a response whose header contains a HTTP 401 Unauthorized status[4] and a WWW-Authenticate field.[5]

    The WWW-Authenticate field for basic authentication (used most often) is constructed as following:

    WWW-Authenticate: Basic realm="User Visible Realm"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流