Does Windows have a default dictionary?

I am trying to make a password complexity indicator for my C ++ / MFC project (using only WinAPI.) Something similar to this:

enter image description here

I can do most of the checks, such as the number of characters, contains letters, numbers, characters, repeated characters, etc., but I also want to add a function to see if any dictionary has used words. This is apparently one of the most important factors determining the strength of the password used.

(For example, a password "Monkey123!"is evaluated as Very Strongif you do not take into account the presence of a dictionary, which actually makes it very weak. Otherwise, it is 10 characters long, has both small and capital letters, has numbers and a punctuation mark. The only warning except using the dictionary , is that it has serial numbers.)

So, I was wondering if there is a list of vocabulary words in Windows (mostly like Linux in /usr/share/dict/words), and if so, how can I use it?

PS. It would be very nice if it were available in Windows XP SP3 and higher.

PS2. So far, all I could come up with was to get a long static dictionary and include it in my project. (Unfortunately, he adds about 1.3 MB to it and hardcodes it only in English.)

+4
source share
2 answers

Windows 8 is the first version of Windows with a built-in spellchecking API , but I don’t think it allows you to access its dictionary directly, you will have to try to find the word boundaries in the password, and the spell checks these words separately to find out if they exist in dictionary.

+2
source

Anders. Windows 8, , ISpellChecker. , , :

#include <Spellcheck.h>

HRESULT hr;

hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
BOOL bInitted = SUCCEEDED(hr);
if (true)
{
    CComPtr<ISpellCheckerFactory> factory;
    if (SUCCEEDED(hr = CoCreateInstance(__uuidof(SpellCheckerFactory),
        nullptr,
        CLSCTX_INPROC_SERVER,
        __uuidof(factory),
        reinterpret_cast<void **>(&factory))))
    {
        BOOL supported;
        if (SUCCEEDED(hr = factory->IsSupported(L"en-US", &supported)))
        {
            if (supported)
            {
                CComPtr<ISpellChecker> checker;
                if (SUCCEEDED(hr = factory->CreateSpellChecker(L"en-US", &checker)))
                {
                    LPCTSTR pText = L"usa"; // L"Cann I I haev some?";  // L"ACLU";

                    CComPtr<IEnumSpellingError> errors;
                    if (SUCCEEDED(hr = checker->Check(pText, &errors)))
                    {
                        for (;;)
                        {
                            CComPtr<ISpellingError> error;
                            hr = errors->Next(&error);
                            if (hr == S_OK)
                            {
                                //Found a spelling error

                                //To get a position of a spelling error
                                ULONG startIndex;
                                ULONG length;
                                VERIFY(SUCCEEDED(hr = error->get_StartIndex(&startIndex)));
                                VERIFY(SUCCEEDED(hr = error->get_Length(&length)));

                                wstring word(pText + startIndex, pText + startIndex + length);

                                //Get corrective action
                                CORRECTIVE_ACTION action;
                                VERIFY(SUCCEEDED(hr = error->get_CorrectiveAction(&action)));

                                //We must have gotten something
                                ASSERT(action != CORRECTIVE_ACTION_NONE);

                                if (action == CORRECTIVE_ACTION_GET_SUGGESTIONS)
                                {
                                    //Spellchecker issued suggestions
                                    TRACE(L"Suggestions for \"%s\":\n", word.c_str());

                                    CComPtr<IEnumString> suggestions;
                                    if (SUCCEEDED(hr = checker->Suggest(word.c_str(), &suggestions)))
                                    {
                                        for (;;)
                                        {
                                            wchar_t* pSuggestion = NULL;
                                            hr = suggestions->Next(1, &pSuggestion, NULL);
                                            if (hr == S_OK)
                                            {
                                                //Got suggestion
                                                ASSERT(pSuggestion);

                                                TRACE(L" - %s\n", pSuggestion);

                                                CoTaskMemFree(pSuggestion);
                                            }
                                            else if (hr == S_FALSE)
                                            {
                                                //No more suggestions
                                                break;
                                            }
                                            else
                                            {
                                                //Some other error
                                                ASSERT(NULL);
                                                break;
                                            }
                                        }
                                    }
                                    else
                                        ASSERT(NULL);
                                }
                                else if (action == CORRECTIVE_ACTION_REPLACE)
                                {
                                    //Spellchecker wants to replace a part of the phrase
                                    wchar_t* pstrReplacement = NULL;
                                    VERIFY(SUCCEEDED(hr = error->get_Replacement(&pstrReplacement)));
                                    ASSERT(pstrReplacement);

                                    TRACE(L"Replace \"%s\" with \"%s\"\n", word.c_str(), pstrReplacement);

                                    CoTaskMemFree(pstrReplacement);
                                }
                                else if (action == CORRECTIVE_ACTION_DELETE)
                                {
                                    //Spellchecker wants to delete a part of the phrase
                                    TRACE(L"Delete \"%s\"\n", word.c_str());
                                }

                            }
                            else if (hr == S_FALSE)
                            {
                                //No more spelling errors
                                break;
                            }
                            else
                            {
                                //Some other error
                                ASSERT(NULL);
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                //Such language is not supported
                ASSERT(NULL);
            }
        }
    }
}

if (bInitted)
{
    ::CoUninitialize();
}

, - :

  • Windows 8.

  • . , usa : use, us user. usa . .

+1

Source: https://habr.com/ru/post/1676340/


All Articles