小编Ven*_*aka的帖子

如何在python代码中使用SHA256-HMAC?

我正在从此URL获取消息和密钥

import hmac
import hashlib
import base64
my = "/api/embedded_dashboard?data=%7B%22dashboard%22%3A7863%2C%22embed%22%3A%22v2%22%2C%22filters%22%3A%5B%7B%22name%22%3A%22Filter1%22%2C%22value%22%3A%22value1%22%7D%2C%7B%22name%22%3A%22Filter2%22%2C%22value%22%3A%221234%22%7D%5D%7D"
key = "e179017a-62b0-4996-8a38-e91aa9f1"
print(hashlib.sha256(my + key).hexdigest())
Run Code Online (Sandbox Code Playgroud)

我得到这个结果:

2df1d58a56198b2a9267a9955c31291cd454bdb3089a7c42f5d439bbacfb3b88
Run Code Online (Sandbox Code Playgroud)

预期结果:

adcb671e8e24572464c31e8f9ffc5f638ab302a0b673f72554d3cff96a692740
Run Code Online (Sandbox Code Playgroud)

python oauth sha256 hmac

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

如何在django中将纯文本转换为哈希密码

我是Django的新手.已经从SQLite迁移到MySQL.用户相关信息存储在auth_user表中.

我有100个用户相关的用户名和密码以纯文本格式.我需要将它们插入到auth_user表中.我怎样才能做到这一点?

例如,我使用下面的insert语句手动插入它们.

INSERT INTO `auth_user` (username, `password`, is_superuser ) 
VALUES ('test', 'test_password', 0)
Run Code Online (Sandbox Code Playgroud)

如果我这样插入它们,我将公开纯文本密码.我想使用Django哈希密码.

python mysql django django-models

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

django中的CSRF令牌丢失或不正确

views.py

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
import MySQLdb
from django.shortcuts import render_to_response
from django.shortcuts import HttpResponseRedirect
from django.template.loader import get_template
from django.template import Context, Template,RequestContext
import datetime
import hashlib
from random import randint
import random
from django.views.decorators.csrf import csrf_protect, csrf_exempt
from django.template.context_processors import csrf
import requests
from django.template import RequestContext
from log.forms import *

@csrf_protect
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
            username=form.cleaned_data['username'],
            password=form.cleaned_data['password1'],
            email=form.cleaned_data['email']
            ) …
Run Code Online (Sandbox Code Playgroud)

python django

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

如何在django中的views.py中登录用户名

其实我对django和python都很新.在/templates/home.html中,添加了{{user.username}},它显示当前登录的用户名

<p>Welcome {{ user.username }} !!!</p>
Run Code Online (Sandbox Code Playgroud)

我想在views.py文件中获取当前登录的用户名.如何获得用户名?

我尝试了不同的方式,但我没有得到结果

  1. user = User.objects.get(username=request.user.username)
  2. username = request.GET['username']
  3. def sample_view(request): current_user = request.user print(current_user)

请告诉我,如何实现我的结果.

我的views.py看起来像这样.我的views.py有什么问题吗?

    #!python
    #log/views.py
    from django.shortcuts import render
    from django.contrib.auth.decorators import login_required
    from django.template import Context
    from contextlib import contextmanager
    # Create your views here.
    # this login required decorator is to not allow to any
    # view without authenticating
    @login_required(login_url="login/")
    def home(request):
         return render(request,"home.html")
#dummy_user = {{ username }}
#user = User.objects.get(username=request.user.username)
#username = request.GET['username'] …
Run Code Online (Sandbox Code Playgroud)

html python authentication django oauth

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

如何在python中解析json字符串?

下面的代码运行正常.

 import json
 json_data = '{"Detail":" Rs. 2000 Topup Rs.1779.99 Talktime","Amount":"2000","Validity":"Unlimited"}'
        json_parsed = json.loads(json_data)
        print(json_parsed['Detail'])
        print(json_parsed['Amount'])
        print(json_parsed['Validity'])
Run Code Online (Sandbox Code Playgroud)

如何在json字符串下解析?以及如何显示所有值?

json_data = '[{"Detail":" Rs. 2000 Topup Rs.1779.99 Talktime","Amount":"2000","Validity":"Unlimited"},{"Detail":" Rs. 1900 Topup Rs.1690.99 Talktime","Amount":"1900","Validity":"Unlimited"}]'
Run Code Online (Sandbox Code Playgroud)

请帮我.

python json

-1
推荐指数
1
解决办法
6885
查看次数

标签 统计

python ×5

django ×3

oauth ×2

authentication ×1

django-models ×1

hmac ×1

html ×1

json ×1

mysql ×1

sha256 ×1