只是将用户名存储在cookie中

问题描述 投票:0回答:1

在应用程序中,我们将UserName值传递给内部API

在对Ajax进行API调用之前,我正在调用一个名为GetUserName()的函数,如下所示。此函数基本上将用户名存储在cookie中。我不想总是让Ajax调用服务器来获取UserName。

码:

function GetUserName()
{

//TODO

1. If UserName Cookie exist, return it.
2. If UserName Cookie doesn't exist, then make Ajax call to server to Get 
   UserName and set the Cookie.

}

正如所说here在客户端存储用户名和密码是不好的做法。

但是想知道在这种情况下只在cookie中存储用户名是不好的做法吗?或者我应该加密UserName

任何帮助都会很棒。

javascript security cookies credentials persistent-storage
1个回答
0
投票

用户可以(并将)编辑cookie并最终使用其他用户的用户名。如果GetUserName函数纯粹是装饰性的,请继续,但是如果你将它用于与会话相关的东西你就会遇到麻烦如果你打算这样做,请参阅OWASP section会话ID和cookie的安全性。

© www.soinside.com 2019 - 2024. All rights reserved.