Hi Folks,
Im trying to make a little hack that helps users logon to different
servers on several domains.
Now i need to test the password age of a user on a server. I got the
usr/pwd/svr cridentials, but how do i connect to the server with the
cridentials, check the pwd age, and close the connection.
I allready got a change password funtion that works, so all i need now
is to test the age before i call it.
The bonus quistion is as follows:
Some of users need to be loged on permanently to some of the server.
How do i connect to the servers on behalf of the users, and refresh the
connection every hour.
Cheers
Stevns
My source (proof of concept):
namespace poc1
{
class Program
{
[StructLayout(LayoutKind.Sequential, CharSet =
CharSet.Unicode)]
public struct USER_INFO_1
{
public string usri1_name;
public string usri1_password;
public int usri1_password_age;
public int usri1_priv;
public string usri1_home_dir;
public string comment;
public int usri1_flags;
public string usri1_script_path;
}
[DllImport("Netapi32.dll")]
extern static int
NetUserChangePassword([MarshalAs(UnmanagedType.LPWStr)] string
domainname, [MarshalAs(UnmanagedType.LPWStr)] string username,
[MarshalAs(UnmanagedType.LPWStr)] string oldpassword,
[MarshalAs(UnmanagedType.LPWStr)] string newpassword);
[DllImport("Netapi32.dll")]
extern static int
NetUserGetInfo([MarshalAs(UnmanagedType.LPWStr)] string servername,
[MarshalAs(UnmanagedType.LPWStr)] string username, int level, out
IntPtr bufptr);
static void Main(string[] args)
{
Console.Write("Username:");
string username = Console.ReadLine();
Console.Write("Old Password:");
string oldpwd = Console.ReadLine();
Console.Write("New Password:");
string newpwd = Console.ReadLine();
Console.Write("Server:");
string server = Console.ReadLine();
if (server == "")
{
server = null;
}
if (NetUserChangePassword(server, username, oldpwd, newpwd)
!= 0)
{
Console.WriteLine("Error Changing User Password");
}
else
{
Console.WriteLine("Userpassword changed");
}
Console.WriteLine("Press enter to continue");
Console.ReadLine();
}
}
}