using System;
using System.Data.SqlClient;

namespace ChangePassword
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			string connstring = GetConnectionString();
			SqlConnection conn = new SqlConnection(connstring);
			for(int i=0; i < 2; i++)
			{
				try
				{
					conn.Open();
					break;
				}
				catch(SqlException ex)
				{
          // 18487 = password expired
          // 18488 = must change password on first login
          if ((ex.Number == 18487) || (ex.Number == 18488))    
					{
						// prompt the user for the new password
						string newpw = PromptPassword();
						// change it on SQL Server
						SqlConnection.ChangePassword(connstring, newpw);
						// fix connection string in config and SqlConnection instance
						// to include the new password
						// reattempt the login
					}
				}
			}
		}

		static string GetConnectionString()
		{
			return "server=.;integrated security=sspi;database=pubs";
		}

		static string PromptPassword()
		{
			return "";
		}
	}
}
