문제

등록 또는 비밀번호 변경 양식에서 사용자가 제공한 비밀번호가 강력한 비밀번호인지 확인하는 가장 좋은 방법은 무엇입니까?

내가 가지고 있는 한 가지 아이디어(파이썬)

def validate_password(passwd):
    conditions_met = 0
    conditions_total = 3
    if len(passwd) >= 6: 
        if passwd.lower() != passwd: conditions_met += 1
        if len([x for x in passwd if x.isdigit()]) > 0: conditions_met += 1
        if len([x for x in passwd if not x.isalnum()]) > 0: conditions_met += 1
    result = False
    print conditions_met
    if conditions_met >= 2: result = True
    return result
도움이 되었습니까?

해결책

1:자주 사용하는 비밀번호 제거
자주 사용하는 비밀번호 목록과 비교하여 입력한 비밀번호를 확인하세요(예:유출된 LinkedIn 비밀번호 목록 중 상위 100,000개의 비밀번호: http://www.adeptus-mechanicus.com/codex/linkhap/combo_not.zip), 반드시 포함하세요. Leetspeek 대체품:A@, E3, B8, S5 등
아래 2부로 이동하기 전에 입력한 문구에서 이 목록에 해당하는 비밀번호 부분을 제거하세요.

2:사용자에게 어떤 규칙도 강요하지 마세요

비밀번호의 황금률은 길수록 좋다는 것입니다.
(대부분의) 사용자는 다음과 같이 하기 때문에 대문자, 숫자 및 기호를 강제로 사용하지 마세요.- 첫 글자를 대문자로 만듭니다.- 번호를 입력하세요 1 마지막에;- 넣어 ! 그 후 기호가 필요한 경우.

대신 비밀번호 강도를 확인하세요.

적절한 출발점은 다음을 참조하세요. http://www.passwordmeter.com/

나는 최소한 다음 규칙을 제안합니다.

Additions (better passwords)
-----------------------------
- Number of Characters              Flat       +(n*4)   
- Uppercase Letters                 Cond/Incr  +((len-n)*2)     
- Lowercase Letters                 Cond/Incr  +((len-n)*2)     
- Numbers                           Cond       +(n*4)   
- Symbols                           Flat       +(n*6)
- Middle Numbers or Symbols         Flat       +(n*2)   
- Shannon Entropy                   Complex    *EntropyScore

Deductions (worse passwords)
----------------------------- 
- Letters Only                      Flat       -n   
- Numbers Only                      Flat       -(n*16)  
- Repeat Chars (Case Insensitive)   Complex    -    
- Consecutive Uppercase Letters     Flat       -(n*2)   
- Consecutive Lowercase Letters     Flat       -(n*2)   
- Consecutive Numbers               Flat       -(n*2)   
- Sequential Letters (3+)           Flat       -(n*3)   
- Sequential Numbers (3+)           Flat       -(n*3)   
- Sequential Symbols (3+)           Flat       -(n*3)
- Repeated words                    Complex    -       
- Only 1st char is uppercase        Flat       -n
- Last (non symbol) char is number  Flat       -n
- Only last char is symbol          Flat       -n

그냥 따라가는 중 비밀번호 측정기 충분하지 않습니다. 왜냐하면 순진한 알고리즘이 보기 때문입니다. 비밀번호1! 좋은데 비해 유난히 약하다.점수를 매길 때 첫 글자의 대문자와 뒤따르는 숫자 및 기호를 무시하십시오(마지막 3개 규칙에 따라).

섀넌 엔트로피 계산
보다: Python에서 엔트로피를 계산하는 가장 빠른 방법

삼:너무 취약한 비밀번호는 허용하지 마세요
사용자가 자멸적인 규칙을 따르도록 강요하기보다는 충분히 높은 점수를 줄 수 있는 모든 것을 허용하세요.얼마나 높은지는 사용 사례에 따라 다릅니다.

그리고 가장 중요한 것은
비밀번호를 수락하고 이를 데이터베이스에 저장하면 꼭 소금을 뿌리고 해시하세요!.

다른 팁

언어에 따라 일반적으로 정규식을 사용하여 다음 사항이 있는지 확인합니다.

  • 최소 1 개의 대문자와 하나의 소문자 문자
  • 숫자 1개 이상
  • 하나 이상의 특수 문자
  • 최소 6자 길이

위의 모든 항목을 요구하거나 강도 측정기 유형의 스크립트를 사용할 수 있습니다.내 강도 측정기의 경우 비밀번호 길이가 올바른 경우 다음과 같이 평가됩니다.

  • 한 가지 조건이 충족되었습니다.약한 암호
  • 두 가지 조건이 충족되었습니다.중간 비밀번호
  • 모든 조건 충족:강력한 비밀번호

위의 내용을 필요에 맞게 조정할 수 있습니다.

객체 지향 접근 방식은 일련의 규칙이 될 것입니다.각 규칙에 가중치를 할당하고 이를 반복합니다.의사 코드에서:

abstract class Rule {

    float weight;

    float calculateScore( string password );

}

총점 계산:

float getPasswordStrength( string password ) {     

    float totalWeight = 0.0f;
    float totalScore  = 0.0f;

    foreach ( rule in rules ) {

       totalWeight += weight;
       totalScore  += rule.calculateScore( password ) * rule.weight;

    }

    return (totalScore / totalWeight) / rules.count;

}

존재하는 문자 클래스의 수를 기반으로 하는 예제 규칙 알고리즘은 다음과 같습니다.

float calculateScore( string password ) {

    float score = 0.0f;

    // NUMBER_CLASS is a constant char array { '0', '1', '2', ... }
    if ( password.contains( NUMBER_CLASS ) )
        score += 1.0f;

    if ( password.contains( UPPERCASE_CLASS ) )
        score += 1.0f;

    if ( password.contains( LOWERCASE_CLASS ) )
        score += 1.0f;

    // Sub rule as private method
    if ( containsPunctuation( password ) )
        score += 1.0f;

    return score / 4.0f;

}

확인해야 할 가장 간단한 두 가지 측정항목은 다음과 같습니다.

  1. 길이.최소 8자를 말하겠습니다.
  2. 비밀번호에 포함된 다양한 문자 클래스의 수입니다.일반적으로 소문자, 대문자, 숫자, 구두점 및 기타 기호입니다.강력한 비밀번호에는 이러한 클래스 중 최소 3개 이상의 문자가 포함됩니다.숫자나 기타 알파벳이 아닌 문자를 강제로 사용하면 사전 공격의 효과가 크게 줄어듭니다.

Cracklib은 훌륭하며 최신 패키지에는 이를 위한 Python 모듈이 있습니다.그러나 CentOS 5와 같이 아직 없는 시스템에서는 시스템 cryptlib에 대한 ctypes 래퍼를 작성했습니다.이는 python-libcrypt를 설치할 수 없는 시스템에서도 작동합니다.그것 하다 ctypes를 사용할 수 있는 Python이 필요하므로 CentOS 5의 경우 python26 패키지를 설치하고 사용해야 합니다.

또한 libcrypt "FascistGecos" 기능과 같이 사용자 이름을 가져와 이를 포함하거나 실질적으로 유사한 비밀번호를 확인할 수 있지만 사용자가 /etc/passwd에 존재하지 않아도 된다는 장점이 있습니다.

나의 ctypescracklib 라이브러리는 github에서 사용할 수 있습니다.

일부 예에서는 다음을 사용합니다.

>>> FascistCheck('jafo1234', 'jafo')
'it is based on your username'
>>> FascistCheck('myofaj123', 'jafo')
'it is based on your username'
>>> FascistCheck('jxayfoxo', 'jafo')
'it is too similar to your username'
>>> FascistCheck('cretse')
'it is based on a dictionary word'

다른 유용한 답변을 읽은 후 다음과 같이 할 것입니다.

-1 사용자 이름과 동일
+0에는 사용자 이름이 포함되어 있습니다.
7자 이상 +1
11자 이상 +1
+1에는 숫자가 포함됩니다.
소문자와 대문자 +1 혼합
+1에는 구두점이 포함되어 있습니다.
+1 인쇄할 수 없는 문자

pwscore.py:

import re
import string
max_score = 6
def score(username,passwd):
    if passwd == username:
        return -1
    if username in passwd:
        return 0
    score = 0
    if len(passwd) > 7:
        score+=1
    if len(passwd) > 11:
        score+=1
    if re.search('\d+',passwd):
        score+=1
    if re.search('[a-z]',passwd) and re.search('[A-Z]',passwd):
        score+=1
    if len([x for x in passwd if x in string.punctuation]) > 0:
        score+=1
    if len([x for x in passwd if x not in string.printable]) > 0:
        score+=1
    return score

사용 예:

import pwscore
    score = pwscore(username,passwd)
    if score < 3:
        return "weak password (score=" 
             + str(score) + "/"
             + str(pwscore.max_score)
             + "), try again."

아마도 가장 효율적이지는 않지만 합리적으로 보입니다.FascistCheck => '사용자 이름과 너무 비슷한 것이 확실하지 않습니다.

'abc123ABC!@£' = 사용자 이름의 상위 집합이 아닌 경우 점수 6/6

어쩌면 점수가 낮아질 수도 있습니다.

개방적이고 자유로운 곳이 있어요 존 더 리퍼 기존 비밀번호 데이터베이스를 확인하는 좋은 방법인 비밀번호 크래커입니다.

글쎄, 이것이 내가 사용하는 것입니다:

   var getStrength = function (passwd) {
    intScore = 0;
    intScore = (intScore + passwd.length);
    if (passwd.match(/[a-z]/)) {
        intScore = (intScore + 1);
    }
    if (passwd.match(/[A-Z]/)) {
        intScore = (intScore + 5);
    }
    if (passwd.match(/\d+/)) {
        intScore = (intScore + 5);
    }
    if (passwd.match(/(\d.*\d)/)) {
        intScore = (intScore + 5);
    }
    if (passwd.match(/[!,@#$%^&*?_~]/)) {
        intScore = (intScore + 5);
    }
    if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) {
        intScore = (intScore + 5);
    }
    if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) {
        intScore = (intScore + 2);
    }
    if (passwd.match(/\d/) && passwd.match(/\D/)) {
        intScore = (intScore + 2);
    }
    if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/)) {
        intScore = (intScore + 2);
    }
    return intScore;
} 

알파벳, 숫자 및 기호를 혼합하는 표준 접근 방식 외에도 지난 주 MyOpenId에 등록했을 때 비밀번호 검사기가 숫자를 추가하거나 알파벳을 비슷한 숫자로 바꾸더라도 비밀번호가 사전 단어를 기반으로 하는지 알려줍니다. ('o' 대신 0을 사용하고, 'i' 대신 '1'을 사용하는 등).

나는 꽤 감동받았습니다.

나는 작은 Javascript 애플리케이션을 작성했습니다.구경하다: 또 다른 비밀번호 측정기.소스를 다운로드하여 GPL에 따라 사용/수정할 수 있습니다.재미있게 보내세요!

누군가 이것이 유용하다고 생각할지는 모르겠지만 pear가 제안한 규칙 세트 아이디어가 정말 마음에 들어서 Python 2.6 클래스 규칙을 작성했습니다(비록 2.5와 호환될 수도 있지만).

import re

class SecurityException(Exception):
    pass

class Rule:
    """Creates a rule to evaluate against a string.
    Rules can be regex patterns or a boolean returning function.
    Whether a rule is inclusive or exclusive is decided by the sign
    of the weight. Positive weights are inclusive, negative weights are
    exclusive. 


    Call score() to return either 0 or the weight if the rule 
    is fufilled. 

    Raises a SecurityException if a required rule is violated.
    """

    def __init__(self,rule,weight=1,required=False,name=u"The Unnamed Rule"):
        try:
            getattr(rule,"__call__")
        except AttributeError:
            self.rule = re.compile(rule) # If a regex, compile
        else:
            self.rule = rule  # Otherwise it's a function and it should be scored using it

        if weight == 0:
            return ValueError(u"Weights can not be 0")

        self.weight = weight
        self.required = required
        self.name = name

    def exclusive(self):
        return self.weight < 0
    def inclusive(self):
        return self.weight >= 0
    exclusive = property(exclusive)
    inclusive = property(inclusive)

    def _score_regex(self,password):
        match = self.rule.search(password)
        if match is None:
            if self.exclusive: # didn't match an exclusive rule
                return self.weight
            elif self.inclusive and self.required: # didn't match on a required inclusive rule
                raise SecurityException(u"Violation of Rule: %s by input \"%s\"" % (self.name.title(), password))
            elif self.inclusive and not self.required:
                return 0
        else:
            if self.inclusive:
                return self.weight
            elif self.exclusive and self.required:
                raise SecurityException(u"Violation of Rule: %s by input \"%s\"" % (self.name,password))
            elif self.exclusive and not self.required:
                return 0

        return 0

    def score(self,password):
        try:
            getattr(self.rule,"__call__")
        except AttributeError:
            return self._score_regex(password)
        else:
            return self.rule(password) * self.weight

    def __unicode__(self):
        return u"%s (%i)" % (self.name.title(), self.weight)

    def __str__(self):
        return self.__unicode__()

누군가가 이것이 유용하다고 생각하기를 바랍니다!

사용 예:

rules = [ Rule("^foobar",weight=20,required=True,name=u"The Fubared Rule"), ]
try:
    score = 0
    for rule in rules:
        score += rule.score()
except SecurityException e:
    print e 
else:
    print score

부인 성명:단위 테스트되지 않음

시간이 있다면 비밀번호 크래커를 실행해 보세요.

비밀번호 강도 검사기 및 시간과 리소스가 있는 경우(여러 개의 비밀번호를 확인하는 경우에만 정당화됨) Rainbow Tables를 사용하세요.

일련의 검사를 통해 최소 기준을 충족하는지 확인합니다.

  • 최소 8자 이상
  • 영숫자가 아닌 기호가 하나 이상 포함되어 있습니다.
  • 사용자 이름/이메일 등이 일치하지 않거나 포함되어 있지 않습니다.

다음은 비밀번호 강도를 보고하는 jQuery 플러그인입니다(직접 시도하지는 않음).http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/

그리고 동일한 내용이 PHP로 포팅되었습니다.http://www.alixaxel.com/wordpress/2007/06/09/php-password-strength-algorithm/

등록 또는 비밀번호 변경 양식에서 사용자가 제공한 비밀번호가 강력한 비밀번호인지 확인하는 가장 좋은 방법은 무엇입니까?

복잡성이나 강점을 평가하지 마십시오. 사용자는 시스템을 속일 방법을 찾거나 너무 좌절하여 떠나게 될 것입니다.그것은 당신에게 상황을 가져올 것입니다 이와 같이.특정 길이만 요구하면 유출된 비밀번호는 사용되지 않습니다.보너스 포인트:구현하는 모든 것이 비밀번호 관리자 및/또는 2FA 사용을 허용하는지 확인하세요.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top