- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我首先要说的是,也许这有点矫枉过正。
在我的登录例程中,我在使用 FormsAuthentication.SetAuthCookie 之前加密了用户的登录 ID。
问题是,如果加密字符串最终包含转义字符,则保存的字符串将被截断以处理转义字符。
我是否应该放弃对用户登录 ID 进行加密的尝试?
或者,有没有办法解决这个问题?
这是一个被截断的示例字符串:<< *€ƒKõ‹¯Þ\0ý´Gv\"þEaÔs0n×\tD¦™s€7Œ>>
最佳答案
当你加密用户id时,你应该使用Base64 encoding这样加密数据将只包含有效字符(字母数字、+、/、=)。
您可能会发现这很有帮助:Convert.ToBase64String(byte[])
例子:
string userId = "Hello";
byte[] encryptedData = GetEncryptedBytes(userId);
string encodedUserId = Convert.ToBase64String(encryptedData);
// encodedUserId is "SGVsbG8="
FormsAuthentication.SetAuthCookie(encryptedUserId);
解码是相反的:
string encodedUserId = "SGVsbG8=";
byte[] encryptedData = Convert.FromBase64String(encodedUserId);
string userId = GetDecryptedString(encryptedData);
关于c# - 使用 FormsAuthentication.SetAuthCookie 存储加密字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8316279/
所以,我在 Controller 中有代码: FormsAuthentication.SetAuthCookie("hello", true);throw new Exception("" + Use
我正在尝试在新环境中设置我的网站,但我遇到了成员(member)提供商的问题。 我可以调用 Membership.ValidateUser,它应该返回 true 和 false。太完美了。 但是,在我
您好,我正在对我的 ASP.Net MVC2 项目进行一些单元测试。我正在使用最小起订量框架。在我的 LogOnController 中, [HttpPost] public ActionResult
在检查用户的凭据并确认它们是正确的之后,我使用 FormsAuthentication.SetAuthCookie("Username", false); 来验证用户。 然后在母版页中,我使用 Pag
我正在开发一个 asp.net mvc 应用程序并创建了我的自定义用户数据库和注册程序(需要电子邮件验证)。我可以将 FormsAuthentication.SetAuthCookie 与我自己的登录
我有一个网络应用程序可以安装在很多域和路径上。 所以: client1Name.{mySite.com} client2Name.{mySite.com} 演示。{mySite.com}/prospe
我正在使用 createuserwizard 控件。在 CreatedUser 事件中,我放置了此代码以将用户添加到角色。 protected void RegisterUser_Create
我首先要说的是,也许这有点矫枉过正。 在我的登录例程中,我在使用 FormsAuthentication.SetAuthCookie 之前加密了用户的登录 ID。 问题是,如果加密字符串最终包含转义字
我正在使用 aspx 和 c# 为登录设置身份验证 cookie。 FormsAuthentication.SetAuthCookie(UserName, True) 我想在同一个 cookie 中存
我似乎找不到这个看似简单的问题的答案。 使用第一个或后者有什么区别?为什么我要使用第一个? 在 MSDNAA 上,我发现以下有关 Formsauthentication.setCookie() 的内容
因此 StackOverflow 上有很多关于此的帖子,但我仍然无法解决我的确切问题。这是要点: 我有一个需要身份验证的网站。我正在使用标准的 .NET FormsAuthentication.Set
我有一些代码用于创建身份验证票证。创建票证后,我们调用SetAuthCookie来设置cookie,例如: FormsAuthentication.SetAuthCookie(username, tr
在我的 MVC 3 应用程序中,我有一个非常基本的 Controller [HttpPost] public ActionResult SignIn(LogonModel logonModel) {
我有一些代码可以用来创建身份验证票证。创建票证后,我们调用 SetAuthCookie 来设置 cookie,例如: FormsAuthentication.SetAuthCookie(usernam
我在测试中使用了 Form Authentication。还有一些测试用户名。但发现指定名称的奇怪问题。这是所有测试名称,只有一个名为 amybeyond 的名称可以在测试中使用。 请帮助检查我的测试
我正在尝试使用基本表单例份验证实现 ASP.NET MVC5 应用程序。所以有我的登录方法: [HttpPost] [AllowAnonymous] public Action
问题一: setAuthCookie 是否比 FormsAuthentication.Encrypt(ticketVariable) 更不安全? 我的意思是,如果有人试图通过修改用户名来修改 setA
好的,我很困惑,asp.net 中的 FormsAuthentication.SetAuthCookie() 是否创建基于 session 的 cookie?从我收集到的将一些东西放入 session
我发现 FormsAuthentication.SetAuthCookie 抛出 NullReferenceException - 未将对象引用设置为天蓝色网站上的异步操作内的对象实例。 我发现了以下
很抱歉,如果这已经被覆盖,但我要拔掉我的头发。我的网站正在使用表单例份验证,当我在//localhost 上测试时它运行良好,但是当我发布到网络时它在 IE9 中不起作用。我已按照教程中列出的所有步骤
我是一名优秀的程序员,十分优秀!