繁体   English   中英

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

[英]submit logon in credential provider

我读过这篇文章来开发我的自定义凭据提供程序。

现在我想测试附加在GitHub中的文章的代码。

  • 我跑

    install.reg文件。

  • 通过更改方案运行代码并在登录屏幕中显示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; } } 

问题是如何提交插入的用户名/密码并在正确的情况下成功登录

你在搜索: LogonUser - MSDN

我使用这个示例windows-credentials-provider 如上所述更改问题中的使用方案,并在此函数中输入用户名/密码。

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;
        }

最后,我可以测试.net自定义凭据提供程序。

这也让我感到很沮丧。 但这只是我对凭据提供程序如何工作以及如何实现其接口的误解。

您实际上并没有自己“提交”凭据。 您只需通过填充_CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION来序列化它们,如上面接受的答案中所示,Windows负责实际将它们提交给Winlogon.exe

然后,您可以在ReportResult()方法中检查提交的结果。

暂无
暂无

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

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