-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# rpg | ||
|
||
Random Password Generator written by Poe(GPT-3.5). | ||
|
||
## Run | ||
|
||
```Python | ||
$ python3 app.py # then open the link: http://127.0.0.1:5000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from flask import Flask, render_template, request | ||
import random | ||
import string | ||
|
||
app = Flask(__name__) | ||
|
||
def genpwd(length): | ||
characters = string.ascii_letters + string.digits + '!@#$%&*-' | ||
password = random.choice(string.ascii_letters + string.digits) # 确保密码不以特殊字符开头 | ||
password += ''.join(random.choice(characters) for _ in range(length - 2)) | ||
password += random.choice(string.ascii_letters + string.digits) # 确保密码不以特殊字符结尾 | ||
return password | ||
|
||
def genpwd2(): | ||
password = '' | ||
for _ in range(3): | ||
segment = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(4)) | ||
password += segment + '-' | ||
password = password[:-1] # 移除末尾的连接符- | ||
return password | ||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def home(): | ||
if request.method == 'POST': | ||
pwda, pwdb = genpwd2(), genpwd(random.randint(8, 12)) | ||
return render_template('index.html', password=pwda, password2=pwdb) | ||
return render_template('index.html') | ||
|
||
if __name__ == '__main__': | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>RPG: Random Password Generator</title> | ||
<style> | ||
body { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background-color: #f2f2f2; | ||
flex-direction: column; | ||
} | ||
|
||
button { | ||
align-self: center; | ||
color: rgb(41, 157, 66); | ||
font-size: 24px; | ||
margin-bottom: 20px; | ||
width: 150px; | ||
height: 50px; | ||
border-radius: 25px; | ||
border: none; | ||
background-color: rgb(41, 157, 66); | ||
color: white; | ||
cursor: pointer; | ||
} | ||
|
||
p { | ||
align-self: center; | ||
font-family: "Ubuntu", sans-serif; | ||
font-size: 30px; | ||
color: black; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<form action="/" method="POST"> | ||
<button type="submit">Generate</button> | ||
</form> | ||
{% if password %} | ||
<p>{{ password }}</p> | ||
{% endif %} | ||
{% if password2 %} | ||
<p>{{ password2 }}</p> | ||
{% endif %} | ||
</body> | ||
</html> |