Beispiel #1
0
        protected static bool ResetAdmin()
        {
            bool bRet = true;

            try
            {
                SBConfigStor.Directory dTmp = new SBConfigStor.Directory();
                if (dTmp == null)
                {
                    Console.Error.WriteLine("ERROR: Couldn't create Directory object!");
                }
                else
                {
                    bool   bRes    = true;
                    string sUserid = "";

                    bool bFound = SBConfigStor.Directory.GetUseridByUsername(g_sAdminUsername, out sUserid);
                    if (!bFound)
                    {
                        // Add admin user before continuing.

                        Console.Error.WriteLine("WARNING: Admin user not found, adding now.");

                        SBConfigStor.Users.User uTmp = new SBConfigStor.Users.User();
                        uTmp.Username = g_sAdminUsername;

                        SBConfigStor.Directory.AddUser(uTmp);

                        bFound = SBConfigStor.Directory.GetUseridByUsername(g_sAdminUsername, out sUserid);
                        if (!bFound)
                        {
                            bRes = false;
                            Console.Error.WriteLine("ERROR: Couldn't find admin user that was just added to the DB!");
                        }
                    }

                    // Set the password
                    if (bRes)
                    {
                        bRes = dTmp.SetPassByUserid(sUserid, g_sAdminUsername.ToUpper(), g_sAdminUsername.ToLower());
                        if (!bRes)
                        {
                            Console.Error.WriteLine("ERROR:  Couldn't set the password.");
                        }
                        else
                        {
                            Console.WriteLine("Admin password was reset.");
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                Console.Error.WriteLine("ERROR: Caught exception: {0}", exc.ToString());
            }

            return(bRet);
        }         // ResetAdmin
Beispiel #2
0
        }         // ResetAdmin

        protected static int SetAdminPassword(string i_sOldPassword, string i_sNewPassword)
        {
            int iExitCode = EXIT_CODE_UNKNOWN_ERROR;

            try
            {
                SBConfigStor.Directory directory = new SBConfigStor.Directory();

                if (directory == null)
                {
                    Console.Error.WriteLine("ERROR: Couldn't create Directory object!");
                }
                else
                {
                    if (directory.Authenticate(g_sAdminUsername, i_sOldPassword))
                    {
                        string sUserid = "";

                        if (SBConfigStor.Directory.GetUseridByUsername(g_sAdminUsername, out sUserid))
                        {
                            bool bRes = directory.SetPassByUserid(sUserid, i_sNewPassword.ToUpper(), i_sNewPassword);
                            if (!bRes)
                            {
                                Console.Error.WriteLine("ERROR: Couldn't set the password.");
                            }
                            else
                            {
                                iExitCode = EXIT_CODE_SUCCESS;
                                Console.WriteLine("Admin password was set to '{0}'.", i_sNewPassword);
                            }
                        }
                        else
                        {
                            // This should not be possible, as we have already authenticated the admin user.

                            Console.Error.WriteLine("ERROR: Admin user not found.");
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("ERROR: Old password incorrect.");
                    }
                }
            }
            catch (Exception exc)
            {
                iExitCode = EXIT_CODE_UNKNOWN_ERROR;
                Console.Error.WriteLine("ERROR: Caught exception: {0}", exc.ToString());
            }

            return(iExitCode);
        }
Beispiel #3
0
        protected static bool AddUser(string i_sUsername, string i_sPassword, string i_sDefaultWebpage)
        {
            bool          bRet  = true;
            StringBuilder sbSql = null;

            try
            {
                SBConfigStor.Directory dTmp = new SBConfigStor.Directory();
                if (dTmp == null)
                {
                    Console.Error.WriteLine("ERROR: Couldn't create Directory object!");
                }
                else
                {
                    bool   bRes    = true;
                    string sUserid = "";


                    // Create the user

                    SBConfigStor.Users.User uTmp = new SBConfigStor.Users.User();
                    uTmp.Username = i_sUsername;

                    SBConfigStor.Directory.AddUser(uTmp);

                    bool bFound = SBConfigStor.Directory.GetUseridByUsername(i_sUsername, out sUserid);
                    if (!bFound)
                    {
                        bRes = false;
                        Console.Error.WriteLine("ERROR: Couldn't find user that was just added to the DB!");
                    }
                    else
                    {
                        Console.WriteLine("  User created.");

                        // Set the password
                        if (bRes)
                        {
                            bRes = dTmp.SetPassByUserid(sUserid, i_sUsername, i_sPassword);
                            if (!bRes)
                            {
                                Console.Error.WriteLine("ERROR:  Couldn't set the password.");
                            }
                            else
                            {
                                Console.WriteLine("  User's password set.");
                            }
                        }

                        if ((i_sDefaultWebpage == null) || (i_sDefaultWebpage.Length <= 0))
                        {
                            // Not an error, just don't do anything.
                        }
                        else
                        {
                            // Set the default webpage
                            sbSql = new StringBuilder();
                            sbSql.AppendFormat("INSERT INTO tblUserParams (uUserId, iParamType, sParamName, sParamValue) VALUES ('{0}', '{1}', '{2}', '{3}');", sUserid, (int)(UserPrefs.eParamType.DefaultWebpage), UserPrefs.eParamType.DefaultWebpage.ToString(), i_sDefaultWebpage);

                            bRes = RunSqlCmd(sbSql.ToString());
                            if (bRes)
                            {
                                Console.WriteLine("  User's default webpage set.");
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                Console.Error.WriteLine("ERROR: Caught exception: {0}", exc.ToString());
            }

            return(bRet);
        }         // AddUser