passport 自动取密码

django settings.py

"""
Django settings for password project.

Generated by ‘django-admin startproject‘ using Django 1.9.5.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ‘twc7jzj(@kgl(jaa6hhy1y1!z(b75_ex^=76a(b6j1u76d3=h!‘

# SECURITY WARNING: don‘t run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    ‘django.contrib.admin‘,
    ‘django.contrib.auth‘,
    ‘django.contrib.contenttypes‘,
    ‘django.contrib.sessions‘,
    ‘django.contrib.messages‘,
    ‘django.contrib.staticfiles‘,
    ‘app01‘,
]

MIDDLEWARE_CLASSES = [
    ‘django.middleware.security.SecurityMiddleware‘,
    ‘django.contrib.sessions.middleware.SessionMiddleware‘,
    ‘django.middleware.common.CommonMiddleware‘,
    #‘django.middleware.csrf.CsrfViewMiddleware‘,
    ‘django.contrib.auth.middleware.AuthenticationMiddleware‘,
    ‘django.contrib.auth.middleware.SessionAuthenticationMiddleware‘,
    ‘django.contrib.messages.middleware.MessageMiddleware‘,
    ‘django.middleware.clickjacking.XFrameOptionsMiddleware‘,
]

ROOT_URLCONF = ‘password.urls‘

TEMPLATES = [
    {
        ‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,
        ‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘)]
        ,
        ‘APP_DIRS‘: True,
        ‘OPTIONS‘: {
            ‘context_processors‘: [
                ‘django.template.context_processors.debug‘,
                ‘django.template.context_processors.request‘,
                ‘django.contrib.auth.context_processors.auth‘,
                ‘django.contrib.messages.context_processors.messages‘,
            ],
        },
    },
]

WSGI_APPLICATION = ‘password.wsgi.application‘

# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    ‘default‘: {
    ‘ENGINE‘: ‘django.db.backends.mysql‘,
    ‘NAME‘:‘fengjian‘,
    ‘USER‘: ‘fengjian‘,
    ‘PASSWORD‘: ‘123456‘,
    ‘HOST‘: ‘127.0.0.1‘,
    ‘PORT‘: ‘3306‘,
    }
}

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        ‘NAME‘: ‘django.contrib.auth.password_validation.UserAttributeSimilarityValidator‘,
    },
    {
        ‘NAME‘: ‘django.contrib.auth.password_validation.MinimumLengthValidator‘,
    },
    {
        ‘NAME‘: ‘django.contrib.auth.password_validation.CommonPasswordValidator‘,
    },
    {
        ‘NAME‘: ‘django.contrib.auth.password_validation.NumericPasswordValidator‘,
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = ‘en-us‘

TIME_ZONE = ‘UTC‘

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = ‘/static/‘

SESSION_COOKIE_AGE = 600

urls.py

"""password URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r‘^$‘, views.home, name=‘home‘)
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r‘^$‘, Home.as_view(), name=‘home‘)
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r‘^blog/‘, include(‘blog.urls‘))
"""
from django.conf.urls import url,include
from django.contrib import admin

urlpatterns = [
    url(r‘^admin/‘, admin.site.urls),
    url(r‘^app01/‘,include(‘app01.urls‘)),

]

passpor document

models.py

from __future__ import unicode_literals

from django.db import models

# Create your models here.

class UserType(models.Model):
    name = models.CharField(max_length=60)

class User(models.Model):
    username = models.CharField(max_length=60)
    password = models.CharField(max_length=60)
    user_type = models.ForeignKey(‘UserType‘)

class UserGroup(models.Model):
    groupname = models.CharField(max_length=60)
    user_group = models.ManyToManyField(‘User‘)

class Asset(models.Model):
    hostname = models.CharField(max_length=60)
    ip = models.GenericIPAddressField()
    asset_usergroup = models.ForeignKey(‘UserGroup‘)

vim paramiko_modle.py

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import paramiko

def paramiko_command(ipaddr,username,timeout=10):

    private_key_path = ‘/root/.ssh/id_rsa‘

    key = paramiko.RSAKey.from_private_key_file(private_key_path)

    ssh = paramiko.SSHClient()

    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    ssh.connect(ipaddr,22,username,pkey=key)

    stdin, stdout, stderr = ssh.exec_command(‘/usr/bin/mkpasswd %s‘ %username)

    return stdout.read().strip()

    ssh.close();

paramiko_command(‘192.168.99.131‘,‘root‘)

urls.py

"""password URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r‘^$‘, views.home, name=‘home‘)
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r‘^$‘, Home.as_view(), name=‘home‘)
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r‘^blog/‘, include(‘blog.urls‘))
"""
from django.conf.urls import url,include
from django.contrib import admin
import views

urlpatterns = [
    url(r‘^admin/‘, admin.site.urls),
    url(r‘^login/‘,views.login),
    url(r‘^index/‘,views.index),
    url(r‘^delete/‘,views.delete),
]

views.py

from django.shortcuts import render,render_to_response,redirect,HttpResponse
import models
import paramiko_modle
# Create your views here.

def login(request):
    ret = {‘status‘:""}
    if request.method == ‘POST‘:
        username = request.POST.get(‘username‘,None)
        print username
        password= request.POST.get(‘password‘,None)

        is_empty = all([username,password])

        print is_empty
        if is_empty:

            request.session[‘is_ssession‘] = {‘username‘:username}

            userobj = models.User.objects.filter(username=username,password=password)
            print userobj

            if userobj:

                return redirect(‘/app01/index/‘)

            else:
                ret[‘status‘] = ‘username or password input error‘
        else:
            ret[‘status‘] = ‘Input is not empty‘

    return render_to_response(‘login.html‘,ret)

def index(request):

    ret = {‘status‘:"",
           ‘data‘:"",
           ‘session‘:"",
           ‘user‘:"",
           ‘ipaddr‘:"",
    }
    ssesiondict = request.session.get(‘is_ssession‘,None)

    if not ssesiondict:
        return  redirect(‘/app01/login/‘)
    else:
        if request.method == ‘POST‘:

            username = request.POST.get(‘username‘,None)
            ip = request.POST.get(‘ip‘,None)

            is_empty = all({username,ip})

            if is_empty:
                result = paramiko_modle.paramiko_command(ip,username)
                ret[‘data‘] = result
                ret[‘session‘] = ssesiondict[‘username‘]
                ret[‘user‘] = username
                ret[‘ipaddr‘] = ip
            else:
                ret[‘status‘] = ‘username or ip is not empty‘

    return  render_to_response(‘index.html‘,ret)

def delete(request):
    del request.session[‘is_ssession‘]
    return  redirect(‘/app01/login/‘)

templates   index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h5>index page  loginusername:{{ session }} </h5>
    <h3><a href="/app01/delete/"> logout </a></h3>

    <form action="/app01/index/" method="POST">
        <table>
            <tr>
                <td>username</td>
                <td><input type="text" name="username" value="{{ user }}" /></td>
            </tr>
            <tr>
                <td>IP</td>
                <td><input type="text" name="ip" value="{{ ipaddr }}" /></td>
            </tr>
            <tr>
                <td>password</td>
                <td><input  type="text" name="password" value="{{ data }}"  /></td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="submit" value="commit" /><span>{{ status }}</span></td>
            </tr>
        </table>
    </form>
</body>
</html>

login.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="POST" action="/app01/login/">
    <p>username:<input type="text" name="username" placeholder="username" /></p>
    <p>password:<input type="text" name="password" placeholder="passpwrd" /></p>
    <input type="submit" value="commit" />
    <label style="color: red">{{ status }}</label>
</form>
</body>
</html>
时间: 2024-11-03 22:04:39

passport 自动取密码的相关文章

一个自动生成密码文件的小程序

1.写一个自动生成密码文件的程序 1.你输入几,文件里面就给你产生多少条密码 2.密码必须包括,大写字母.小写字母.数字.特殊字符 3.密码不能重复 4.密码都是随机产生的 5.密码长度6-11 方法一(自己写的) import random,stringf=open('pwd.txt','w') #w覆盖原来产生的文件num=input('请输入你要产生的密码个数:')s = set() while True: random_num=str(random.randint(1,999999))

day4 自动生成密码文件 &amp; 注册

#写一个自动生成密码文件的程序 # 1 输入几,文件里面就产生多少条密码 input #2 密码必须包含 大写字母 小写字母 数字 特殊字符 #3 密码不能重复 #4 密码都是随机产生的 #5 密码长度6-11位 import string,random pwd_len = input('请输入你要产生多少条密码:').strip() pwds = set() #存放所有的密码 if pwd_len.isdigit(): pwd_len = int(pwd_len) while len(pwds

关于.net 保存 decimal类型数据到SQLServer2012数据库时自动取整的问题

公司同事问我有没有遇到过decimal类型数据入库时,会自动取整的问题(比如12.3入库后值是12,12.8入库后值是13,入库后自动四舍五入自动取整): 之前就遇到过从数据去decimal类型数据时,会自动取整的问题:我想应该是同样的问题吧,叫同事设置SQLParameter参数时,设置Scale=2,Precision=18:类似代码如下: var param1 = new SqlParameter("@Money",System.Data.SqlDbType.Decimal);

关于谷歌浏览器下自动填写密码的bug

有的时候我们需要用到h5中input的新类型,type=password 这个可以很好的将输入的内容变成圆点,但是这样做也有一个小bug就是在某些我们不希望自动保存密码的页面中,也会出现浏览器自动帮我们填入密码,比如修改密码页面中 这个旧密码的输入框只要鼠标焦点失去时为空就会帮我们自动填入一个密码,你还不知道帮你填的是你什么时候保存过的,就连清楚浏览器缓存都不行,实在很烦人,那么如果避免这个小bug呢,那就是不用password 这其实有很多办法,最简单的方法是这么写 <input type=t

如何禁用Chrome浏览器的自动保存密码提示

说明,在网页开发中,在表单中加入autocomplete="off"后,IE和FF不会提示保存密码,但是用Chrome浏览器登录系统时,会弹出自动保存密码的提示,从安全的角度考虑,需要禁止浏览器的这个功能,提升系统安全性. 大部分浏览器都是根据表单域的type="password"来判断密码域的,所以针对这种情况可以采取"动态设置密码域"的方法: <input type="text" name="passwor

C# 实现对接电信交费易自动缴费 续(winio/winring0 自动填密码)

自动填密码大家可能都不莫生,最有名的应该是 按键精灵 只要是一个可以输入的地方都可以能过按键精灵来完成输入.我今天要讲的是使用 winio/winring0来完成类似的功能 如果要自动填充密码方式基本上有 消息级的模拟 和 驱动级的模拟, 消息级的模拟如 C# 直接使用 SendKeys 就可以完成 API下可以使用 SendMessage完成 即有了这个神器为什么还要用三方? 答案:现在一些网都使用了ActiveX安全插件,如网银,支付宝,等,还有我们上一次说到的 翼支付和手机支付 它们基本上

javascript 下拉列表 自动取值 无需value

<select id="applyType" name="$!{status.expression}" class="inp" onchange="receiptAddApplyType()" style="width:150px;"> #foreach($item in ${applyTypes}) <option value="$!{item.value}" #if

配置windows自动修改密码和自动登录

日常运维多台服务器,每季度要修改一次密码,非常麻烦,现做一个VBS脚本,每季度第一天定时运行,则可解决该问题,具体实现脚本如下:autochg_pwd.vbs ystr=year(Now)mstr=Month(Now)if len(mstr)<2 then mstr="0"&mstrdstr=day(Now)if mstr="01" then mstr="!"if mstr="02" then mstr=&quo

RunAs 增强性扩展命令(支持自动提交密码,安全授权)

1.问题或需求描述 1>企业网络环境中的软件安装授权问题,通常普通用户不具有管理员权限,但是安装或使用相关软件时却必须要以管理员权限运行,能否只针对单个程序进行授权,而且必须要保护管理员密码. 2>其他种种环境之下,要以其他用户凭据运行目标程序文件的,要求密码受保护,并且命令行信息不可篡改,不能通过替换目标程序的方式非法获得授权. 2.解决方法或原理:对于用户凭据.命令行信息.目标程序文件Md5值进行一并加密并保存于文件中,通过转移或传送加密文件的形式进行授权,解密过程在内存中操作完成并及时销