- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在用 Python 编写一个简单的脚本,用于在评分系统上评估密码的强度,评分系统根据密码是否包含学校的大写或小写字母、数字和符号来给分和取分。
其中一个要求是检查英国标准键盘上从左到右连续的 3 个字母或数字,每个实例扣 5 分。例如,密码“qwer123”会因为“qwe”、“wer”和“123”而失去 15 分。这怎么可能实现呢?我当前的代码如下。
def check():
user_password_score=0
password_capitals=False
password_lowers=False
password_numbers=False
password_symbols=False
password_explanation_check=False
ascii_codes=[]
password_explanation=[]
print("The only characters allowed in the passwords are upper and lower case letters, numbers and these symbols; !, $, %, ^, &, *, (, ), _, -, = and +.\n")
user_password=str(input("Enter the password you would like to get checked: "))
print("")
if len(user_password)>24 or len(user_password)<8:
print("That password is not between 8 and 24 characters and so the Password Checker can't evaluate it.")
menu()
for i in user_password:
ascii_code=ord(i)
#print(ascii_code)
ascii_codes.append(ascii_code)
#print(ascii_codes)
for i in range(len(ascii_codes)):
if ascii_codes[i]>64 and ascii_codes[i]<90:
password_capitals=True
elif ascii_codes[i]>96 and ascii_codes[i]<123:
password_lowers=True
elif ascii_codes[i]>47 and ascii_codes[i]<58:
password_numbers=True
elif ascii_codes[i] in (33,36,37,94,38,42,40,41,45,95,61,43):
password_symbols=True
else:
print("Your password contains characters that aren't allowed.\n")
menu()
if password_capitals==True:
user_password_score+=5
if password_lowers==True:
user_password_score+=5
if password_numbers==True:
user_password_score+=5
if password_symbols==True:
user_password_score+=5
if password_capitals==True and password_lowers==True and password_numbers==True and password_symbols==True:
user_password_score+=10
if password_numbers==False and password_symbols==False:
user_password_score-=5
if password_capitals==False and password_lowers==False and password_symbols==False:
user_password_score-=5
if password_capitals==False and password_lowers==False and password_numbers==False:
user_password_score-=5
#print(user_password_score)
if user_password_score>20:
print("Your password is strong.\n")
else:
print("That password is weak.\n")
#don't forget you still need to add the thing that checks for 'qwe' and other stuff.
menu()
最佳答案
您可以将禁止序列存储在一组字符串中,并在每次有人使用该序列时递减分数。
password = "qwert123"
score = 42 # initial score
sequences = { # all in lowercase because of the `lower()` in the loop
"qwertyuiopasdfghjklzxcvbnm",
"azertyuiopqsdfghjklmwxcvbn",
"abcdefghijklmnopqrstuvwxyz",
"01234567890"
}
match_length = 3 # length threshold for the sanction
sequences.update({s[::-1] for s in sequences}) # do we allow reverse ?
for c in range(len(password)-match_length+1):
for seq in sequences:
if password[c:c+match_length].lower() in seq:
score-=5
print(f"'{password[c:c+match_length]}' => -5 !")
break # Don't flag the same letters more than once
print(score) # 22 (42-4*5)
关于python - 统计多个子串同时出现在一个字符串中的次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54737088/
我目前正在学习数据挖掘,有以下问题。 机器学习和数据挖掘之间有什么关系? 我发现许多数据挖掘技术都与统计相关,而我“听说”数据挖掘与机器学习有很多关系。所以我的问题是:机器学习与统计学密切相关吗? 如
我有很多表的数据,例如: event_id player finish 1 a 1 1 b 2 1 c
我对 http_status_module 提供的统计数据感兴趣 特别是上游部分的统计数据。 http://nginx.org/en/docs/http/ngx_http_status_module.
除了 Cluster MBean 之外,是否有任何可以在 Akka (Java) 中启用的内置 JMX 公开监控/统计信息?我看过 Typesafe Console,但由于它需要许可证才能用于从多个节
我正在尝试在我的程序中使用“usage”统计信息来获取类似于 time 的数据工具。但是,我很确定我做错了什么。这些值似乎是正确的,但有时可能有点奇怪。我没有在网上找到好的资源。有人知道如何做得更好吗
我有一个带有统计表的 MySQL 数据库。我想以年历、月度的形式输出数据。对于没有点击率的几个月,我想花费一个“空”DIV。有两个ID。 $query = mysqli_query($db,"SELE
设置: 问题是经典概率问题的复杂形式: 70 colored balls are placed in an urn, 10 for each of the seven rainbow colors.
有哪些 Ruby gem 可以执行数据处理? 最佳答案 我知道有 3 种从 Ruby 访问 R 的方法: RinRuby RSRuby 通过 Rserve-Ruby-Client 预约 RinRuby
背景 图像领域内的一个国内会议快要召开了,要发各种邀请邮件,之后要录入、统计邮件回复(参会还是不参会等)。如此重要的任务,老师就托付给我了。ps: 统计回复邮件的时候,能知道谁参会或谁不参会。
我正在添加用户输入的几个数字并将它们添加到数组列表中。 到目前为止我的代码: package project143; import java.util.*; /** * @author -- */
正如标题所示,我需要做的是在各种 iO/Android/Windows 应用程序中跟踪各种用户事件 - 例如点击、滑动、在页面上花费的时间等。 这些应用程序基于响应式 HTML/CSS/JS,并具有简
我希望计算 HTML 表中每个唯一值的实例数,并在其自己的表中返回结果。该表是根据用户的文本输入生成的。例如,用户输入可能如下所示: Report 46 Bob Marley 4/20/2
如何使用 PHP 计算数字数组的 z 分数?我需要计算 z 分数,然后找到百分位数 (CDF)!我可以使用哪些 PHP 函数?谢谢! 最佳答案 以下代码将给出 CDF 的良好近似值(Abramowit
我只是想知道是否可以计算 GitHub 上空存储库的总数。 如果不适合所有用户,可以为自己做吗? 编辑 我已经尝试过size:0搜索,但似乎返回了很多包含数据的存储库。采用 size:0..1 之类的
public class Scanner { private HtmlProcessor hp; private String baseUrl; private int ste
我正在使用 Mule ESB 3.4。我想开发一个自定义 Java 组件来计算流收到的请求数量。流程将例如像这样: http inbound-endpoint -> counter -> vm-out
我喜欢借助 GitHub API 来统计存储库中所有开放的拉取请求和问题。我发现 API 端点 /repos/:owner/:repo 结果包含 open_issues 属性。然而,这是问题和拉取请求
如何使用 PHP 计算数字数组的 z 分数?我需要计算 z 分数,然后找到百分位数 (CDF)!我可以使用哪些 PHP 函数?谢谢! 最佳答案 以下代码将给出 CDF 的良好近似值(Abramowit
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在尝试以编程方式获取搜索字词列表的 Google 新闻搜索结果计数(即有多少个结果),但仅限于过去 1 年。使用用户界面搜索时,结果计数仅出现在常规搜索中,但在“工具 > 最近 > 过去一年”下时
我是一名优秀的程序员,十分优秀!