【问题标题】:How to create a hashed email in jQuery?如何在 jQuery 中创建散列电子邮件?
【发布时间】:2013-08-25 20:38:33
【问题描述】:

我需要在 jQuery 中对电子邮件进行哈希处理,以便与 Gravatar 一起使用。

所以:

http://www.gravatar.com/avatar/user@email.com

会变成:

http://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50

我能够从 Python/Mako 获取电子邮件并将其传递到我的 jQuery 类中。

var gravatar_placeholder = $('#modal-vcard .vcard_profile_pic img').prop('src');
var substr = gravatar_placeholder.split('__gravatar__').join(their_email);

用户的电子邮件是their_email,我需要在上面第二行之前在 jquery/javascript 中进行哈希处理,以便生成Gravatar

我在这里找到了this answer,但在我的情况下无法使用它。

有什么建议吗?你会如何处理这个问题?

【问题讨论】:

  • 在将其发送到 jQuery 之前,最好在 python 中执行此操作

标签: javascript jquery email hash


【解决方案1】:

这是另一个使用加密库的示例

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
<script>
var hash = CryptoJS.MD5("name@test.com");
var img = new Image();
img.src = "http://www.gravatar.com/avatar/" + hash;
document.body.appendChild(img);
</script>

【讨论】:

  • 太棒了,这超级容易:)
【解决方案2】:

有几种哈希算法,我不确定您要使用哪一种,但 MD5 是一种非常流行的哈希算法。

例如,someemail@test.com 在 MD5 中散列为 9cb0cbcda88377b1e1d66e8d7f01cbae

https://github.com/blueimp/JavaScript-MD5

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-21
  • 1970-01-01
  • 1970-01-01
  • 2017-10-24
  • 2013-07-25
  • 2014-09-05
相关资源
最近更新 更多