🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# / bilgisayarın kullanıcı adı ve parola dogru ise dogru diyor

 

1-) C# -  bilgisayarın kullanıcı adı ve parola dogru ise dogru diyor

using System.Security.Principal;

using System.Security.Permissions;

using System.Runtime.InteropServices;

public void cagir()

        {

            IntPtr tokenHandle = new IntPtr(0);

            try

            {

                string UserName = null;

                string MachineName = null;

                string Pwd = null;

                //The MachineName property gets the name of your computer.

                MachineName = System.Environment.MachineName;

                UserName = textBox1.Text;

                Pwd = textBox2.Text;

                const int LOGON32_PROVIDER_DEFAULT = 0;

                const int LOGON32_LOGON_INTERACTIVE = 2;

                tokenHandle = IntPtr.Zero;

                //Call the LogonUser function to obtain a handle to an access token.

                bool returnValue = LogonUser(UserName, MachineName, Pwd, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out tokenHandle);

                if (returnValue == false)

                {

                    //This function returns the error code that the last unmanaged function returned.

                    int ret = Marshal.GetLastWin32Error();

                    string errmsg = GetErrorMessage(ret);

                    MessageBox.Show(errmsg);

                }

                else

                {

                    //Create the WindowsIdentity object for the Windows user account that is

                    //represented by the tokenHandle token.

                    WindowsIdentity newId = new WindowsIdentity(tokenHandle);

                    WindowsPrincipal userperm = new WindowsPrincipal(newId);

                    //Verify whether the Windows user has administrative credentials.

                    if (userperm.IsInRole(WindowsBuiltInRole.Administrator))

                    {

                        MessageBox.Show("Access Granted. User is admin");

                    }

                    else

                    {

                        MessageBox.Show("Access Granted. User is not admin");

                    }

                }

                CloseHandle(tokenHandle);

            }

            catch (Exception ex)

            {

                MessageBox.Show("Exception occurred. " + ex.Message);

            }

        }

 2021 Ocak 18 Pazartesi
 455