小编ksh*_*hen的帖子

在Python/Django中是否有相当于PHP的hash_hmac?

我想将访问者转发给第三方付费网站.第三方将使用sha256算法使用PHP的hash_hmac处理他们的付款和POST给我一个64个字符的令牌,该令牌来自一个唯一的订单号和共享密码,如下所示:

$token = hash_hmac("sha256", "12345", "sharedpassword");
Run Code Online (Sandbox Code Playgroud)

然后我想在我的端部使用相同的算法来生成(希望)相同的令牌以验证用户已付款.问题是我找不到一个等效的函数或方法来复制Python中的函数.我最接近的是Python的hashlib,但似乎没有一个函数可以接受2个参数 - 数据和共享密码.有没有人知道在这种情况下适用的hash_hmac等价物?

php python django sha256

23
推荐指数
1
解决办法
6118
查看次数

尝试为Google身份验证器插入QR代码图像时出现400错误请求

我正在尝试在我的网站上使用Google身份验证器设置双因素身份验证.我能够生成工作代码,但是当我将图像URL插入页面时,我在Chrome检查器中收到以下错误:

GET https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/MyLabel?secret=THESECRET 400 (Bad Request)
Run Code Online (Sandbox Code Playgroud)

生成QR码的代码:

try
  key = crypto.randomBytes(10).toString('hex')
catch error
  console.log "error generating code: #{error}"
encoded = base32.encode(key)
label = encodeURIComponent "MyLabel"
uri = "otpauth://totp/#{label}?secret=#{encoded}"
url = "https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=#{uri}"
Run Code Online (Sandbox Code Playgroud)

插入图像的客户端jQuery:

img = $("<img>").attr("src", url)
$("#qr_box").html("")
$("#qr_box").append(img)
Run Code Online (Sandbox Code Playgroud)

这导致页面上出现以下HTML:

<img src="https://www.google.com/chart?chs=200x200&amp;chld=M|0&amp;cht=qr&amp;chl=otpauth://totp/MyLabel?secret=THESECRET">
Run Code Online (Sandbox Code Playgroud)

可以在新选项卡中打开图像而不会出现问题.图像仅在我的页面中成功显示约1/10的时间; 其他时候Chrome给了400.我在这里错过了一些明显的东西吗?

authentication google-authentication node.js coffeescript

6
推荐指数
1
解决办法
1627
查看次数

在鼠标悬停时,更改图像的不透明度并覆盖文本

我想在鼠标悬停在缩略图图像上时删除不透明度和叠加文本.我有几个关于如何做的想法,但我相当肯定他们效率低,笨拙.

  1. 使用文本叠加和降低的不透明度在Photoshop中制作复制图像.鼠标悬停时将原件换成副本.
  2. 使用CSS在鼠标悬停时删除不透明度.使用Javascript切换包含叠加文本的div的可见性.

我看到1的问题是它似乎不必要地使用空间和带宽,并且会导致加载时间变慢.使用2,似乎我必须在每个div的位置进行硬编码,这对维护和更新来说是一种痛苦.我知道这是一个有点普遍的问题,但我对如何解决这个问题感到茫然.如何以一种易于添加新缩略图的方式完成这个相对简单的任务?

html javascript css jquery overlay

3
推荐指数
1
解决办法
3万
查看次数

使用参数'()'和未找到关键字参数'{}'来反转''*''

我正在尝试使用该{% url %}标记将我的用户发送到名为payment.html的新模板.我收到上面的错误.这就是我所拥有的:

在我的模板中的一些Javascript中:

  {% url 'payment' %}
Run Code Online (Sandbox Code Playgroud)

在我的网址中:

  urlpatterns = patterns('',
    (r'media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),

    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^pc-admin/', include(pcAdminSite.urls)),

    (r'^$', index),
    (r'^signup/', signup),
    (r'^info_submit/', info_submit),
    (r'^payment/', payment, name="payment"),
Run Code Online (Sandbox Code Playgroud)

在我看来:

  def payment(request):
    return render_to_response('payment.html', {})
Run Code Online (Sandbox Code Playgroud)

基于类似的帖子,我确保只有1个网址指向我的付款视图并使用了命名网址.任何人都可以帮助解决我可能做错的事情吗?谢谢.

python django django-templates

3
推荐指数
1
解决办法
8743
查看次数

从C++调用C库

我有一个由其他人编写的C库,我希望从我的C++程序中调用它.C头的结构如下:

#ifndef INC_MOVE_CLIENT_H
#define INC_MOVE_CLIENT_H

#ifdef __cplusplus
    extern "C" {
#endif

...

int serverConnect(const char *, const char *, MoveStateDeferred *);

...

#ifdef __cplusplus
}
#endif

#endif  // ... INC_MOVE_CLIENT_H
Run Code Online (Sandbox Code Playgroud)

我在我的C++程序中调用serverConnect,如下所示:

#include "helloworld.h"
#include "moveclient.h"

int main(int argc, const char* argv[]) {
    const char* ip = "192.168.1.2";
    const char* port = "7899";
    MoveStateDeferred* m;
    serverConnect(ip, port, m);
}
Run Code Online (Sandbox Code Playgroud)

根据这些说明,对我来说似乎是正确的,但当我尝试编译时,我得到:

$ gcc helloworld.cpp -o helloworld.out
/tmp/ccuS93Yu.o: In function `main':
helloworld.cpp:(.text+0x3c): undefined reference to `serverConnect'
collect2: ld returned …
Run Code Online (Sandbox Code Playgroud)

c c++

2
推荐指数
1
解决办法
3297
查看次数