1

I have a windows forms project that uses PrincipalContext.ValidateCredentials Method

Everything works fine, but...

First, a user logs in to windows environment by using his/her windows username and password. Then, this user logs in to my app by using his/her windows username and password. This is a duplicate work isn't ?

My goal is to create something like SSMS's windows authentication (if you connect to DB selecting windows authentication it doesn't ask for your windows password because you are already logged in). So I want to get currently logged-in user's username and something like (Hash, GUID, SID etc.) and use that info to authenticate user.

Is there any way to achieve this ?

MickyD
  • 13,463
  • 6
  • 39
  • 60
Eldar Zeynalov
  • 351
  • 4
  • 17
  • https://stackoverflow.com/questions/10608486/how-to-get-current-windows-login-name-in-c-sharp-web-app – Amit Kumar Singh Aug 20 '17 at 19:41
  • @amit how is that relevant? – MickyD Aug 20 '17 at 20:40
  • Possible duplicate of [Authenticate user in WinForms (Nothing to do with ASP.Net)](https://stackoverflow.com/questions/22873717/authenticate-user-in-winforms-nothing-to-do-with-asp-net) – pinkfloydx33 Aug 20 '17 at 21:06
  • @MickyD User has not mentioned whether it is webapp or windows forms app. He just mentions environment is windows. If it is windows app, i think that will be far easier to log in with user credentials automatically. – Amit Kumar Singh Aug 21 '17 at 01:32
  • 1
    I guess you would need to provide more details about - why do you use `ValidateCredentials` ? In a WinForms application, [WindowsIdentity.GetCurrent()](https://docs.microsoft.com/en-us/dotnet/api/system.security.principal.windowsidentity.getcurrent?view=netframework-4.7#System_Security_Principal_WindowsIdentity_GetCurrent) gives the current Windows user. There is no need to do "authentication" again. It is already the authenticated user. – Subbu Aug 21 '17 at 02:21
  • 1
    @Amit. Incorrect - _"I have a windows forms project"_ – MickyD Aug 21 '17 at 02:46
  • @Amit User already mentioned its a windows forms project – Sandeep Thomas Jan 17 '19 at 10:12

0 Answers0