Beispiel #1
0
        public User loginDA(User user)
        {
            PasswordProtection pp = new PasswordProtection();
            var hashedPassowrd    = pp.GenerateSHA256(user.password);

            Dictionary <string, SqlParameter> queryParameters = new Dictionary <string, SqlParameter>();

            queryParameters["userName"] = new SqlParameter("userName", user.userName);
            queryParameters["password"] = new SqlParameter("password", hashedPassowrd);

            try
            {
                SqlDataReader reader = SqlDatabaseUtility.ExecuteQuery("[dbo].[Login]", queryParameters);
                while (reader.Read() == true)
                {
                    if (reader.GetInt32(reader.GetOrdinal("id")) > 0)
                    {
                        user.id       = reader.GetInt32(reader.GetOrdinal("id"));
                        user.userName = reader.GetString(reader.GetOrdinal("userName"));
                        user.role     = reader.GetInt32(reader.GetOrdinal("role"));
                    }
                    else
                    {
                        user.userName = null;
                        user.role     = 0;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("OOPs, something went wrong.\n" + e);
            }

            return(user);
        }
        public void LoginCLI()
        {
            User user                  = new User();
            PasswordProtection pp      = new PasswordProtection();
            AccountDA          account = new AccountDA();

            Console.WriteLine("--------- Welcome |  Login the System to continue ----------");
            Console.WriteLine("");
            Console.WriteLine("User Name: ");
            user.userName = Console.ReadLine();
            Console.WriteLine("Password: "******"successfully Login...!");
                Console.Clear();
            }
            else
            {
                Console.WriteLine("Invalied Login Attempt...!");
            }
        }
        public void UpdatePasswordCLI()
        {
            User               user   = new User();
            UserDA             userDA = new UserDA();
            PasswordProtection pp     = new PasswordProtection();

            user.id = AccountCLI.currentUserID;

            Console.WriteLine("Enter your current password: "******"Enter Your New Password :"******"Re-Enter your new password : "******"oops, password you entered did not match- try again...");
                Console.WriteLine("");
                UpdatePasswordCLI();
            }
        }
Beispiel #4
0
 public AccountSettings(TimeSpan deleteDelay, int accountsPerIP = 1,
                        int housesPerAccount     = 2, int maxHousesPerAccount  = 4,
                        bool autoAccountCreation = true, bool restrictDeletion = true,
                        PasswordProtection passwordProtection = PasswordProtection.NewCrypt)
 {
     this._AccountsPerIP       = accountsPerIP;
     this._HousesPerAccount    = housesPerAccount;
     this._MaxHousesPerAccount = maxHousesPerAccount;
     this._AutoAccountCreation = autoAccountCreation;
     this._RestrictDeletion    = restrictDeletion;
     this._DeleteDelay         = deleteDelay;
     this.m_PasswordProtection = passwordProtection;
 }
Beispiel #5
0
 public AccountSettings(int accountsPerIP = 1, int housesPerAccount = 2,
     int maxHousesPerAccount = 4, bool autoAccountCreation = true,
     bool restrictDeletion = true, TimeSpan deleteDelay = TimeSpan.FromDays(7.0),
     PasswordProtection passwordProtection = PasswordProtection.NewCrypt)
 {
     this._AccountsPerIP = accountsPerIP;
     this._HousesPerAccount = housesPerAccount;
     this._MaxHousesPerAccount = maxHousesPerAccount;
     this._AutoAccountCreation = autoAccountCreation;
     this._RestrictDeletion = restrictDeletion;
     this._DeleteDelay = deleteDelay;
     this.m_PasswordProtection = passwordProtection;
 }
Beispiel #6
0
        public void UpdateUserCLI()
        {
            User               user   = new User();
            AdminDA            admin  = new AdminDA();
            PasswordProtection pp     = new PasswordProtection();
            ExcuteAdminCLI     excute = new ExcuteAdminCLI();

            Console.WriteLine("");
            Console.WriteLine("+++ Update User Details +++");
            Console.WriteLine("");

            ViewUserCLI();

            Console.WriteLine("");
            Console.WriteLine("enter user id that want to change details :");
            user.id = Int32.Parse(Console.ReadLine());

            Console.WriteLine("enter user name :");
            user.userName = Console.ReadLine();

            Console.WriteLine("enter user password :"******"enter user role :");
            Console.WriteLine("");
            Console.WriteLine("1 - admin");
            Console.WriteLine("2 - Team Lead");
            Console.WriteLine("3 - Normal Member");
            Console.WriteLine("");
            Console.WriteLine("Enter respective number : ");
            user.role = Int32.Parse(Console.ReadLine());

            var msg = admin.UpdateUserDA(user);

            Console.WriteLine(msg);

            Console.Clear();
            excute.HeaderInfo();
            ViewUserCLI();

            Console.WriteLine("");
            Console.WriteLine("** press [Esc] back to menu");

            var k = Console.ReadKey(true);

            if (k.Key == ConsoleKey.Escape)
            {
                Console.Clear();
                excute.Header();
            }
        }
Beispiel #7
0
        public void CreateUsersCLI()
        {
            User               user   = new User();
            AdminDA            admin  = new AdminDA();
            PasswordProtection pp     = new PasswordProtection();
            ExcuteAdminCLI     excute = new ExcuteAdminCLI();

            Console.WriteLine("");
            Console.WriteLine("+++ Add New User +++");
            Console.WriteLine("");

            Console.WriteLine("enter user name :");
            user.userName = Console.ReadLine();

            Console.WriteLine("enter user password :"******"enter user role :");
            Console.WriteLine("");
            Console.WriteLine("1 - admin");
            Console.WriteLine("2 - Team Lead");
            Console.WriteLine("3 - Normal Member");
            Console.WriteLine("");
            Console.WriteLine("Enter respective number : ");
            user.role = Int32.Parse(Console.ReadLine());

            Console.WriteLine("");
            Console.WriteLine("** press [Esc] to save and exit");
            Console.WriteLine("** press [1] to save and add new user");

            var k = Console.ReadKey(true);

            if (k.Key == ConsoleKey.Escape)
            {
                var msg = admin.CreateUsersDA(user);
                Console.WriteLine(msg);
                Console.Clear();
                excute.Header();
            }
            else if (k.Key == ConsoleKey.NumPad1 || k.Key == ConsoleKey.D1)
            {
                var mmsg = admin.CreateUsersDA(user);
                Console.WriteLine(mmsg);
                Console.Clear();
                excute.HeaderInfo();
                CreateUsersCLI();
            }
        }
Beispiel #8
0
		public AccountSettings(
			TimeSpan deleteDelay,
			int accountsPerIP = 1,
			int housesPerAccount = 2,
			int maxHousesPerAccount = 4,
			bool autoAccountCreation = true,
			bool restrictDeletion = true,
			PasswordProtection passwordProtection = PasswordProtection.NewCrypt)
		{
			AccountsPerIP = accountsPerIP;
			HousesPerAccount = housesPerAccount;
			MaxHousesPerAccount = maxHousesPerAccount;
			AutoAccountCreation = autoAccountCreation;
			RestrictDeletion = restrictDeletion;
			DeleteDelay = deleteDelay;
			PasswordProtection = passwordProtection;
		}
Beispiel #9
0
        public sealed override void Deserialize(GenericReader reader)
        {
            int version = reader.ReadInt();

            switch (version)
            {
            case 0:
            {
                this._AccountsPerIP       = reader.ReadInt();
                this._HousesPerAccount    = reader.ReadInt();
                this._MaxHousesPerAccount = reader.ReadInt();
                this._AutoAccountCreation = reader.ReadBool();
                this._RestrictDeletion    = reader.ReadBool();
                this._DeleteDelay         = reader.ReadTimeSpan();
                this.m_PasswordProtection = (PasswordProtection)reader.ReadByte();
                break;
            }
            }
        }
Beispiel #10
0
        public override void Deserialize(GenericReader reader)
        {
            int version = reader.ReadInt();

            switch (version)
            {
            case 0:
            {
                AccountsPerIP       = reader.ReadInt();
                HousesPerAccount    = reader.ReadInt();
                MaxHousesPerAccount = reader.ReadInt();
                AutoAccountCreation = reader.ReadBool();
                RestrictDeletion    = reader.ReadBool();
                DeleteDelay         = reader.ReadTimeSpan();
                PasswordProtection  = (PasswordProtection)reader.ReadByte();
            }
            break;
            }
        }
        public string UpdatePasswordDA(User user)
        {
            string             msg = "";
            PasswordProtection pp  = new PasswordProtection();
            var hashedPassowrd     = pp.GenerateSHA256(user.password);

            Dictionary <string, SqlParameter> cmdParameters = new Dictionary <string, SqlParameter>();

            cmdParameters["id"]       = new SqlParameter("id", user.id);
            cmdParameters["password"] = new SqlParameter("password", hashedPassowrd);
            int rc = SqlDatabaseUtility.ExecuteCommand("[dbo].[UpdateUsers]", cmdParameters);

            if (rc == -1)
            {
                msg = "Password updated successfully...!";
            }
            else
            {
                msg = "OOPs, something went wrong...!";
            }
            return(msg);
        }
Beispiel #12
0
        public void DeleteUserCLI()
        {
            User               user   = new User();
            AdminDA            admin  = new AdminDA();
            PasswordProtection pp     = new PasswordProtection();
            ExcuteAdminCLI     excute = new ExcuteAdminCLI();

            Console.WriteLine("");
            Console.WriteLine("+++ Delete User Details +++");
            Console.WriteLine("");

            ViewUserCLI();

            Console.WriteLine("");
            Console.WriteLine("enter user id that want to delete :");
            user.id = Int32.Parse(Console.ReadLine());


            var msg = admin.DeleteUserDA(user);


            Console.Clear();
            excute.HeaderInfo();
            Console.WriteLine("");
            Console.WriteLine(msg);
            Console.WriteLine("");
            ViewUserCLI();

            Console.WriteLine("");
            Console.WriteLine("** press [Esc] back to menu");

            var k = Console.ReadKey(true);

            if (k.Key == ConsoleKey.Escape)
            {
                Console.Clear();
                excute.Header();
            }
        }
Beispiel #13
0
        public string CreateUsersDA(User user)
        {
            string             msg = "";
            PasswordProtection pp  = new PasswordProtection();
            var hashedPassowrd     = pp.GenerateSHA256(user.password);

            Dictionary <string, SqlParameter> cmdParameters = new Dictionary <string, SqlParameter>();

            cmdParameters["userName"] = new SqlParameter("userName", user.userName);
            cmdParameters["password"] = new SqlParameter("password", hashedPassowrd);
            cmdParameters["role"]     = new SqlParameter("role", user.role);
            int rc = SqlDatabaseUtility.ExecuteCommand("[dbo].[InsertUser]", cmdParameters);

            if (rc == -1)
            {
                msg = "user create successfully...!";
            }
            else
            {
                msg = "OOPs, something went wrong...!";
            }
            return(msg);
        }
Beispiel #14
0
		public override void Deserialize(GenericReader reader)
		{
			int version = reader.ReadInt();

			switch (version)
			{
				case 0:
					{
						AccountsPerIP = reader.ReadInt();
						HousesPerAccount = reader.ReadInt();
						MaxHousesPerAccount = reader.ReadInt();
						AutoAccountCreation = reader.ReadBool();
						RestrictDeletion = reader.ReadBool();
						DeleteDelay = reader.ReadTimeSpan();
						PasswordProtection = (PasswordProtection)reader.ReadByte();
					}
					break;
			}
		}
Beispiel #15
0
        public static void UpdateDBPasswords( )
        {
            //Console.WriteLine( "Exporting New Passwords..." );
            try
            {
                ArrayList      ToUpdatePWFromUO = new ArrayList( );
                OdbcConnection Connection       = new OdbcConnection(ConnectionString);

                Connection.Open( );
                OdbcCommand Command = Connection.CreateCommand( );

                Command.CommandText = string.Format("SELECT name,password FROM {0} WHERE state='{1}'", DatabaseTable, ( int )Status.Active);
                OdbcDataReader reader = Command.ExecuteReader( );

                QueryCount += 1;

                while (reader.Read( ))
                {
                    string username = reader.GetString(0);
                    string password = reader.GetString(1);

                    Account AtoUpdate = Accounts.GetAccount(username) as Account;

                    if (AtoUpdate != null)
                    {
                        PasswordProtection PWMode   = AccountHandler.ProtectPasswords;
                        string             Password = "";

                        switch (PWMode)
                        {
                        case PasswordProtection.None: { Password = AtoUpdate.PlainPassword; } break;

                        case PasswordProtection.Crypt: { Password = AtoUpdate.CryptPassword; } break;

                        default: { Password = AtoUpdate.NewCryptPassword; } break;
                        }

                        if (Password == null || Password == "" || Password != password)
                        {
                            ToUpdatePWFromUO.Add(AtoUpdate);
                        }
                    }
                }
                reader.Close( );

                //Console.WriteLine( "Updating Database..." );
                foreach (Account a in ToUpdatePWFromUO)
                {
                    PasswordProtection PWModeU   = AccountHandler.ProtectPasswords;
                    string             PasswordU = "";

                    switch (PWModeU)
                    {
                    case PasswordProtection.None: { PasswordU = a.PlainPassword; } break;

                    case PasswordProtection.Crypt: { PasswordU = a.CryptPassword; } break;

                    default: { PasswordU = a.NewCryptPassword; } break;
                    }

                    QueryCount += 1;

                    Command.CommandText = string.Format("UPDATE {0} SET state='{1}',password='******' WHERE name='{3}'", DatabaseTable, ( int )Status.Active, PasswordU, a.Username);
                    Command.ExecuteNonQuery( );
                }

                Connection.Close( );

                Console.WriteLine("[{0} Database Passwords Changed] ", ToUpdatePWFromUO.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine("[Database Password Change] Error...");
                Console.WriteLine(e);
            }
        }
Beispiel #16
0
        protected override sealed void Deserialize(GenericReader reader)
        {
            int version = reader.ReadInt();

            switch (version)
            {
                case 0:
                    {
                        this._AccountsPerIP = reader.ReadInt();
                        this._HousesPerAccount = reader.ReadInt();
                        this._MaxHousesPerAccount = reader.ReadInt();
                        this._AutoAccountCreation = reader.ReadBool();
                        this._RestrictDeletion = reader.ReadBool();
                        this._DeleteDelay = reader.ReadTimeSpan();
                        this.m_PasswordProtection = (PasswordProtection)reader.ReadByte();
                        break;
                    }
            }
        }
Beispiel #17
0
        public static void CreateAccountsFromUO( )
        {
            //Console.WriteLine( "Exporting New Accounts..." );
            try
            {
                ArrayList      ToCreateFromUO = new ArrayList( );
                OdbcConnection Connection     = new OdbcConnection(ConnectionString);

                Connection.Open( );
                OdbcCommand Command = Connection.CreateCommand( );

                Command.CommandText = string.Format("SELECT name FROM {0}", DatabaseTable);
                OdbcDataReader reader = Command.ExecuteReader( );

                QueryCount += 1;

                while (reader.Read( ))
                {
                    string username = reader.GetString(0);

                    Account toCheck = Accounts.GetAccount(username) as Account;

                    if (toCheck == null)
                    {
                        ToCreateFromUO.Add(toCheck);
                    }
                }
                reader.Close( );

                //Console.WriteLine( "Updating Database..." );
                foreach (Account a in ToCreateFromUO)
                {
                    int ALevel = 0;

                    if (a.AccessLevel == AccessLevel.Player)
                    {
                        ALevel = 1;
                    }
                    else if (a.AccessLevel == AccessLevel.Counselor)
                    {
                        ALevel = 2;
                    }
                    else if (a.AccessLevel == AccessLevel.GameMaster)
                    {
                        ALevel = 3;
                    }
                    else if (a.AccessLevel == AccessLevel.Seer)
                    {
                        ALevel = 4;
                    }
                    else if (a.AccessLevel == AccessLevel.Administrator)
                    {
                        ALevel = 6;
                    }

                    PasswordProtection PWMode   = AccountHandler.ProtectPasswords;
                    string             Password = "";

                    switch (PWMode)
                    {
                    case PasswordProtection.None: { Password = a.PlainPassword; } break;

                    case PasswordProtection.Crypt: { Password = a.CryptPassword; } break;

                    default: { Password = a.NewCryptPassword; } break;
                    }

                    QueryCount += 1;

                    OdbcCommand InsertCommand = Connection.CreateCommand( );

                    InsertCommand.CommandText = string.Format("INSERT INTO {0} (name,password,email,access,timestamp,state) VALUES( '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')", DatabaseTable, a.Username, Password, a.Email, ALevel, ToUnixTimestamp(a.Created), ( int )Status.Active);
                    InsertCommand.ExecuteNonQuery( );
                }

                Connection.Close( );

                Console.WriteLine("[{0} Database Accounts Added] ", ToCreateFromUO.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine("[Database Account Create] Error...");
                Console.WriteLine(e);
            }
        }