【问题标题】:Is it possible to see if a string contains [multiple] dictionary words?是否可以查看字符串是否包含 [多个] 字典单词?
【发布时间】:2021-02-25 17:59:04
【问题描述】:

目前,我有一个单词表 (~250k),我希望能够检测用户的 [新] P/W 是否包含在表中定义的零个、一个或多个字典单词。我认为下面的比较会发送一条错误消息,其中只有 1 个字典单词,但有一个示例 P/W 字符串(至少有 4 个单词,不包括 Be-My)“ThisWillBeMyPassPhrase2!1!”仍然被抓住。任何想法如何解决这个问题?

''' 打开word_list; 环形 获取 word_list 到 word_rec; word_list%notfound 时退出;

if instr(nls_lower(password),nls_lower(word_rec.word)) = 1 then
  raise_application_error(-20003, 'New password should have only ONE word or be a Passphrase');
end if;

结束循环; '''

错误消息:ORA-20003:新密码应该只有一个单词或密码短语 28003. 00000 - “指定密码的密码验证失败” *原因:新密码没有达到必要的复杂度

【问题讨论】:

    标签: sql oracle oracle-sqldeveloper


    【解决方案1】:

    你当前的伪代码:

    for i := 1 to dictionary_size do 
      if dictionary_word(i) is in candidate_password exactly 1 time then 
        stop the "if" and the "for" and raise app error;
      end if; 
    end for;
    

    应该是这样的:

    counter := 0;
    for i := 1 to dictionary_size do
      if dictionary_word(i) is in candidate_password exactly 1 time then
        counter := counter + 1;
      end if;
    end for;
    if counter = 1 then
      raise app error;
    end if;
    

    【讨论】:

      【解决方案2】:

      像这样循环遍历行集并不是一个好主意。逐行是缓慢的。最好完全在 SQL 中一步完成。比如:

      select count(*) from (
          select dt.word 
            from dictionary_table dt
           where instr( lower( dt.word ), lower( password )) > 0
           fetch first 2 rows only
      )
      

      fetch first 2 rows only 之所以存在,是因为您只关心是否存在密码短语,而不关心其中是否有 2 个或 7 个单词。因此,一旦您找到两个匹配的单词,您就知道您有密码并且可以停止。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-17
        • 2016-11-06
        相关资源
        最近更新 更多