passport 自动取密码
django settings.py
"""
Django settings for password project. Generated by 'django-admin startproject' using Django 1.9.. 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': '',
'HOST': '127.0.0.1',
'PORT': '',
}
} # 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 =
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
. Add an import: from my_app import views
. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
. Add an import: from other_app.views import Home
. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
. Import the include() function: from django.conf.urls import url, include
. 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=) class User(models.Model):
username = models.CharField(max_length=)
password = models.CharField(max_length=)
user_type = models.ForeignKey('UserType') class UserGroup(models.Model):
groupname = models.CharField(max_length=)
user_group = models.ManyToManyField('User') class Asset(models.Model):
hostname = models.CharField(max_length=)
ip = models.GenericIPAddressField()
asset_usergroup = models.ForeignKey('UserGroup')
vim paramiko_modle.py
#!/usr/bin/env python
#-*- coding:utf- -*- import paramiko def paramiko_command(ipaddr,username,timeout=): 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,,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
. Add an import: from my_app import views
. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
. Add an import: from other_app.views import Home
. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
. Import the include() function: from django.conf.urls import url, include
. 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>
passport 自动取密码的更多相关文章
- 关于谷歌浏览器下自动填写密码的bug
有的时候我们需要用到h5中input的新类型,type=password 这个可以很好的将输入的内容变成圆点,但是这样做也有一个小bug就是在某些我们不希望自动保存密码的页面中,也会出现浏览器自动帮我 ...
- C# 实现对接电信交费易自动缴费 续(winio/winring0 自动填密码)
原文:C# 实现对接电信交费易自动缴费 续(winio/winring0 自动填密码) 自动填密码大家可能都不莫生,最有名的应该是 按键精灵 只要是一个可以输入的地方都可以能过按键精灵来完成输入.我今 ...
- 关于.net 保存 decimal类型数据到SQLServer2012数据库时自动取整的问题
公司同事问我有没有遇到过decimal类型数据入库时,会自动取整的问题(比如12.3入库后值是12,12.8入库后值是13,入库后自动四舍五入自动取整): 之前就遇到过从数据去decimal类型数据时 ...
- mac securecrt自动保存密码
一.问题描述 mac有自带的终端,可以运行ssl和sftp,但是目录操作,文件操作和文件上传是分开的,很不方便,并且文件上传命令需要文件的全路路径. 使用securecrt能方便的解决上述的问题,并且 ...
- 解决chrome浏览器自动填充密码
chrome会自动填充密码,解决方法很简单 使用下面的参考代码即可: <input type="password" readonly οnfοcus="this.r ...
- Golang对方法接收者变量的自动“取引用”和“解引用”
原文:https://blog.csdn.net/u014633283/article/details/83826413 --------------------------------------- ...
- chrome表单禁止自动填充密码
在用户登录成功以后,chrome会提示用户记住密码. 用户退出以后若前往注册.忘记密码页时会自动填充密码. 若不希望自动填充密码,只需在input里设置autoComplete="new-p ...
- 配置windows自动修改密码和自动登录
日常运维多台服务器,每季度要修改一次密码,非常麻烦,现做一个VBS脚本,计划任务设置每季度第一天三点定时运行,则可解决该问题,具体实现脚本如下:autochg_pwd.vbs ystr=year(No ...
- chrome防止自动填充密码
是防止,不是禁止.禁止需要在浏览器设置. chrome浏览器保存密码之后,页面上有password存在的时候会出现自动填充用户名和密码的情况. 添加disableautocomplete和autoco ...
随机推荐
- OpenCV学习笔记——形态学梯度操作
代码: #include<cv.h> #include<highgui.h> int main(void) { cvNamedWindow("cmp"); ...
- PAT天梯赛练习题 L3-010. 是否完全二叉搜索树(完全二叉树的判断)
L3-010. 是否完全二叉搜索树 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 将一系列给定数字顺序插入一个初始为空的二叉搜 ...
- Sql Group by 使用
CREATE TABLE StuCourseScore ( ID int, Name nvarchar(10), Course nvarchar(10), Score int ) INSERT Stu ...
- html 实体转换为字符:转换 UEditor 编辑器 ( 在 ThinkPHP 3.2.2 中 ) 保存的数据
在 ThinkPHP 3.2.2 中使用 UEditor 编辑器保存文章内容时,数据库中保存的数据都被转义成实体,例如:<p><strong>& ...
- adId、idfv
//广告标示符,适用于对外:例如广告推广,换量等跨应用的用户追踪等. NSString *adId = [[[ASIdentifierManager sharedManager] advertisin ...
- xml提取
$url = 'http://221.232.141.108/hsdcw/news.xml'; $opts = array( 'http'=>array( 'method'=>" ...
- laravel 视图组件
假设有一个文件被多个视图需要,比如导航条: 1.在路由文件添加 View::composer('stats', function($view){ $view->with('stats', app ...
- SQL_NO_CACHE
http://dev.mysql.com/doc/refman/5.7/en/query-cache-in-select.html MySQL 5.7 Reference Manual / ... ...
- 实验三--for语句及分支结构else-if
本节课学习到的知识点: 1.for语句的表达式的应用与掌握.流程形式. 2.多分支else-if,用来判断真假等. 实验中遇到的问题及解决方法: 这次课的逻辑要求比之前的课要难许多,而且对于一些数学逻 ...
- BlueDroid代码分析之GKI
目录 1. 概述 2. 线程 2.1 主要函数 2.2 功能 3. 事件 3.1 主要函数 3.2 功能 1. 概述 GKI以库libbt-brcm_gki.so(Static Lib?)的形式提供给 ...