简体   繁体   English

提交凭据提供程序中的登录

[英]submit logon in credential provider

I have read this article to develop my custom credential provider. 我读过这篇文章来开发我的自定义凭据提供程序。

Now I want to test code attached with the article in GitHub . 现在我想测试附加在GitHub中的文章的代码。

  • I run 我跑

    install.reg file. install.reg文件。

  • run the code and show GUI in login screen by change scenario 通过更改方案运行代码并在登录屏幕中显示GUI

      private static bool IsSupportedScenario(_CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus) { switch (cpus) { case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_CREDUI: return true; case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_UNLOCK_WORKSTATION: return true; case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_LOGON: return true; case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_CHANGE_PASSWORD: case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_PLAP: case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_INVALID: default: return false; } } 

the question is how can I submit an inserted username/password and log in successfully if correct 问题是如何提交插入的用户名/密码并在正确的情况下成功登录

你在搜索: LogonUser - MSDN

I use this sample windows-credentials-provider . 我使用这个示例windows-credentials-provider Change usage scenarios as above in the question and put username/password in this function. 如上所述更改问题中的使用方案,并在此函数中输入用户名/密码。

public int GetSerialization(out _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE pcpgsr,
            out _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION pcpcs, out string ppszOptionalStatusText,
            out _CREDENTIAL_PROVIDER_STATUS_ICON pcpsiOptionalStatusIcon)
        {
            Log.LogMethodCall();

            try
            {
                pcpgsr = _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE.CPGSR_RETURN_CREDENTIAL_FINISHED;
                pcpcs = new _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION();

                var username = "Domain\\username";
                var password = "password";
                var inCredSize = 0;
                var inCredBuffer = Marshal.AllocCoTaskMem(0);

                if (!PInvoke.CredPackAuthenticationBuffer(0, username, password, inCredBuffer, ref inCredSize))
                {
                    Marshal.FreeCoTaskMem(inCredBuffer);
                    inCredBuffer = Marshal.AllocCoTaskMem(inCredSize);

                    if (PInvoke.CredPackAuthenticationBuffer(0, username, password, inCredBuffer, ref inCredSize))
                    {
                        ppszOptionalStatusText = string.Empty;
                        pcpsiOptionalStatusIcon = _CREDENTIAL_PROVIDER_STATUS_ICON.CPSI_SUCCESS;

                        pcpcs.clsidCredentialProvider = Guid.Parse(Constants.CredentialProviderUID);
                        pcpcs.rgbSerialization = inCredBuffer;
                        pcpcs.cbSerialization = (uint)inCredSize;

                        RetrieveNegotiateAuthPackage(out var authPackage);
                        pcpcs.ulAuthenticationPackage = authPackage;

                        return HResultValues.S_OK;
                    }

                    ppszOptionalStatusText = "Failed to pack credentials";
                    pcpsiOptionalStatusIcon = _CREDENTIAL_PROVIDER_STATUS_ICON.CPSI_ERROR;
                    return HResultValues.E_FAIL;
                }
            }
            catch (Exception)
            {
                // In case of any error, do not bring down winlogon
            }
            finally
            {
                shouldAutoLogin = false; // Block auto-login from being stupid
            }

            pcpgsr = _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE.CPGSR_NO_CREDENTIAL_NOT_FINISHED;
            pcpcs = new _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION();
            ppszOptionalStatusText = string.Empty;
            pcpsiOptionalStatusIcon = _CREDENTIAL_PROVIDER_STATUS_ICON.CPSI_NONE;
            return HResultValues.E_NOTIMPL;
        }

Finally I can test .net custom credential provider. 最后,我可以测试.net自定义凭据提供程序。

This was hanging me up for awhile, too. 这也让我感到很沮丧。 But it was just my misunderstanding of how the credential providers work and how to implement their interfaces. 但这只是我对凭据提供程序如何工作以及如何实现其接口的误解。

You don't actually "submit" the credentials yourself. 您实际上并没有自己“提交”凭据。 You just serialize them as shown in the accepted answer above by populating _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION, and Windows takes care of actually submitting them to Winlogon.exe 您只需通过填充_CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION来序列化它们,如上面接受的答案中所示,Windows负责实际将它们提交给Winlogon.exe

You can then check the result of the submittal in the ReportResult() method. 然后,您可以在ReportResult()方法中检查提交的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM