Ejemplo n.º 1
0
        private int CreateUserDevice(MasterLogin pMasterLogin, LoginRequest pLoginRequest)
        {
            int             lResult;
            IUserRepository _IUserRepository = new UserRepository(new WorkersInMotionDB());
            UserDevice      lUserDevice      = new UserDevice();

            lUserDevice.UserDevicesGUID  = Guid.NewGuid();
            lUserDevice.LoginGUID        = pMasterLogin.LoginGUID;
            lUserDevice.UserGUID         = pMasterLogin.UserGUID;
            lUserDevice.IPAddress        = pLoginRequest.DeviceInfo.deviceipaddress;
            lUserDevice.DeviceID         = pLoginRequest.DeviceInfo.deviceid;
            lUserDevice.DeviceInfo       = new JavaScriptSerializer().Serialize(pLoginRequest.DeviceInfo);
            lUserDevice.DeviceType       = pLoginRequest.DeviceInfo.devicetype;
            lUserDevice.PUSHID           = pLoginRequest.PushID;
            lUserDevice.Phone            = pMasterLogin.Phone;
            lUserDevice.IsActive         = true;
            lUserDevice.TimeZone         = pLoginRequest.DeviceInfo.TimeZone;
            lUserDevice.CreateDate       = DateTime.UtcNow;
            lUserDevice.CreateBy         = pMasterLogin.UserGUID;
            lUserDevice.LastModifiedDate = DateTime.UtcNow;
            lUserDevice.LastModifiedBy   = pMasterLogin.UserGUID;
            // _IUserRepository.InsertUserDevice(lUserDevice);
            if (_IUserRepository.InsertUserDevice(lUserDevice) > 0)
            {
                lResult = 1;
            }
            else
            {
                lResult = 0;
            }
            return(lResult);
        }
Ejemplo n.º 2
0
        private void OnExportPublicKeyConfirmMsg(ExportPublicKeyConfirmMsg msg)
        {
            _isProcessInProgress = true;
            UIServices.SetBusyState();
            _logger.Info("export public key confirmed --> export key file");
            _logger.Info("export path: " + msg.Filename);

            MasterLogin login = _database.GetAll <MasterLogin>().FirstOrDefault();

            if (login != null)
            {
                bool success = _cryptographyService.ExportPublicKeyFile(msg.Filename, login.PublicKey);

                if (success)
                {
                    _logger.Info("export successful");
                    _messenger.Send(new ExportPublicKeySuccsessMsg());
                }
                else
                {
                    _logger.Error("export failed");
                    _messenger.Send(new ExportPublicKeyFailedMsg());
                }
            }
            else
            {
                _logger.Error("login is null!");
            }

            _isProcessInProgress = false;
        }
Ejemplo n.º 3
0
        private int CreateMasterLogin(MasterLogin pMasterLogin)
        {
            int             lResult;
            IUserRepository _IUserRepository = new UserRepository(new WorkersInMotionDB());
            MasterLogin     lMasterLogin     = new MasterLogin();

            lMasterLogin.LoginGUID        = Guid.NewGuid();
            lMasterLogin.LoginType        = pMasterLogin.LoginType;
            lMasterLogin.UserGUID         = pMasterLogin.UserGUID;
            lMasterLogin.IsActive         = true;
            lMasterLogin.SessionID        = Guid.NewGuid().ToString();
            lMasterLogin.ExpiryTime       = pMasterLogin.ExpiryTime;
            lMasterLogin.SessionTimeOut   = 60;
            lMasterLogin.IsLoggedIn       = true;
            lMasterLogin.Phone            = "";
            lMasterLogin.CreateDate       = DateTime.UtcNow;
            lMasterLogin.CreateBy         = pMasterLogin.UserGUID;
            lMasterLogin.LastModifiedDate = DateTime.UtcNow;
            lMasterLogin.LastModifiedBy   = pMasterLogin.UserGUID;
            //_IUserRepository.InsertMasterLogin(lMasterLogin);
            if (_IUserRepository.InsertMasterLogin(lMasterLogin) > 0)
            {
                pMasterLogin.SessionID = lMasterLogin.SessionID;
                lResult = 1;
            }
            else
            {
                lResult = 0;
            }
            return(lResult);
        }
Ejemplo n.º 4
0
        private void Decrypt(object obj)
        {
            _isProcessInProgress = true;
            UIServices.SetBusyState();

            _logger.Info("start decryption");
            _logger.Info("source: " + SourceFilepath);
            _logger.Info("destination: " + TargetFilepath);
            _logger.Info("sender: " + ContactName);

            if (CheckSoureAndTargetPath())
            {
                if (IsVaildFile())
                {
                    MasterLogin login = _database.GetAll <MasterLogin>().FirstOrDefault();

                    if (login != null)
                    {
                        bool isDecryped = _cryptographyService.DecryptFile(_sourceFilepath, _targetFilepath,
                                                                           login.PrivateKey);

                        if (isDecryped)
                        {
                            _messenger.Send(new DecryptionSuccsessMsg());
                        }
                        else
                        {
                            _logger.Error("file can not decrypt!");
                            _messenger.Send(new DecryptionFailedMsg());
                        }

                        _logger.Info("check if source file in temp directory and when it is, then delete");
                        CheckSourceFileInTempDirectory();

                        //reset inputs
                        SourceFilepath = string.Empty;
                        TargetFilepath = string.Empty;
                        ContactName    = string.Empty;
                    }
                    else
                    {
                        _logger.Error("login is null!");
                    }
                }
                else
                {
                    _logger.Error("file is not vaild for encryption! maybe encrpytion?");
                    _messenger.Send(new DecryptionFailedMsg());
                }
            }
            else
            {
                _logger.Error("source and/or target path are not vaild!");
                _messenger.Send(new SourceTargetInvaildMsg());
            }

            _disableForEncryption = true;
            _isProcessInProgress  = false;
        }
Ejemplo n.º 5
0
        private void Encrypt(object obj)
        {
            _isProcessInProgress = true;
            UIServices.SetBusyState();

            _logger.Info("start encryption");
            _logger.Info("source: " + _sourceFilepath);
            _logger.Info("destination: " + _targetFilepath);
            _logger.Info("receipient: " + _contactName);

            if (CheckSoureAndTargetPath())
            {
                if (string.IsNullOrEmpty(ContactName))
                {
                    MasterLogin login = _database.GetAll <MasterLogin>().FirstOrDefault();

                    if (login != null)
                    {
                        _logger.Info("encrpyt file for myself");

                        _cryptographyService.EncryptFile(_sourceFilepath, _targetFilepath, login.PublicKey);
                        _messenger.Send(new EncryptionSuccsessMsg {
                            TargetPath = _targetFilepath + ".sfs"
                        });
                    }
                    else
                    {
                        _logger.Error("login is null!");
                    }
                }
                else
                {
                    _logger.Info("encrpyt file for: " + ContactName);

                    _cryptographyService.EncryptFile(_sourceFilepath, _targetFilepath, PublicKey);
                    _messenger.Send(new EncryptionSuccsessMsg {
                        TargetPath = _targetFilepath
                    });
                }

                _logger.Info("check if source file in temp directory and when it is, then delete");
                CheckSourceFileInTempDirectory();

                //reset inputs
                SourceFilepath = string.Empty;
                TargetFilepath = string.Empty;
                ContactName    = string.Empty;
            }
            else
            {
                _logger.Error("source and/or target path are not vaild!");
                _messenger.Send(new SourceTargetInvaildMsg());
            }

            _disableForEncryption = true;
            _isProcessInProgress  = false;
        }
        public void Insert()
        {
            List <Contact> contacts = _dataAccess.GetAll <Contact>();

            Assert.IsTrue(contacts.Count == 0);

            List <MasterLogin> materLogins = _dataAccess.GetAll <MasterLogin>();

            Assert.IsTrue(materLogins.Count == 0);

            var hybridEncrypter = new HybridRsaAes();

            hybridEncrypter.AssignNewRSAKeys();

            var contact = new Contact
            {
                Name      = "Marcel",
                PublicKey = hybridEncrypter.GetPublicRSAKey()
            };

            _dataAccess.Insert(contact);

            contacts = _dataAccess.GetAll <Contact>();
            Assert.IsTrue(contacts.Count == 1);

            var salt = PBKDF2Impl.GenerateSalt();

            hybridEncrypter = new HybridRsaAes();
            hybridEncrypter.AssignNewRSAKeys();

            var materLogin = new MasterLogin
            {
                Name       = "MasterMan",
                Password   = PBKDF2Impl.HashPassword(Encoding.UTF8.GetBytes("password123"), salt),
                Salt       = salt,
                PrivateKey = hybridEncrypter.GetPrivateRSAKeyAsXml(),
                PublicKey  = hybridEncrypter.GetPublicRSAKey()
            };

            _dataAccess.Insert(materLogin);

            materLogins = _dataAccess.GetAll <MasterLogin>();
            Assert.IsTrue(materLogins.Count == 1);
        }
Ejemplo n.º 7
0
        private void SaveNewCredentialsExecute(object parametar)
        {
            try
            {
                var passwordBox = parametar as PasswordBox;
                var password    = passwordBox.Password;

                if (MasterLogin.ChangeCredentials(username, password) == true)
                {
                    MessageBox.Show("Successful Changed Credentials");
                    CloseChangePassAndUser();
                }
                else
                {
                    MessageBox.Show("Invalid new credentials!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 8
0
        //public GlobalUser DeviceLogin(GlobalUser plGlobalUser)
        //{
        //    GlobalUser lGlobalUser = new GlobalUser();
        //    return lGlobalUser;
        //}

        //public GetUsers GetUserFromClient(Guid UserGUID, Guid OrganizationGUID)
        //{
        //    string UserType = GetUserType(UserGUID);
        //    GetUsers _getUsers = new GetUsers();
        //    List<GlobalUser> globalUser = new List<GlobalUser>();
        //    List<UserProfile> userProfile = new List<UserProfile>();
        //    if (!string.IsNullOrEmpty(UserType))
        //    {
        //        //if (UserType == "ENT_A")
        //        //{
        //        //    using (var dataContext = new WorkersInMotionContext())
        //        //    {

        //        //        globalUser = (from p in dataContext.GlobalUser
        //        //                      where p.OrganizationGUID == OrganizationGUID
        //        //                      select p).ToList();
        //        //        foreach (GlobalUser item in globalUser)
        //        //        {
        //        //            userProfile.Add((from p in dataContext.UserProfile
        //        //                             where p.UserGUID == item.UserGUID
        //        //                             select p).SingleOrDefault());
        //        //        }
        //        //    }
        //        //}
        //        //else if (UserType == "ENT_U_RM")
        //        //{
        //        //    using (var dataContext = new WorkersInMotionContext())
        //        //    {

        //        //        globalUser = (from p in dataContext.GlobalUser
        //        //                      where p.OrganizationGUID == OrganizationGUID && (p.UserType == "ENT_U_RM" || p.UserType == "ENT_U_TM" || p.UserType == "ENT_U")
        //        //                      select p).ToList();
        //        //        foreach (GlobalUser item in globalUser)
        //        //        {
        //        //            userProfile.Add((from p in dataContext.UserProfile
        //        //                             where p.UserGUID == item.UserGUID
        //        //                             select p).SingleOrDefault());
        //        //        }
        //        //    }
        //        //}
        //        //else if (UserType == "ENT_U_TM")
        //        //{
        //        //    using (var dataContext = new WorkersInMotionContext())
        //        //    {

        //        //        globalUser = (from p in dataContext.GlobalUser
        //        //                      where p.OrganizationGUID == OrganizationGUID && (p.UserType == "ENT_U_TM" || p.UserType == "ENT_U")
        //        //                      select p).ToList();
        //        //        foreach (GlobalUser item in globalUser)
        //        //        {
        //        //            userProfile.Add((from p in dataContext.UserProfile
        //        //                             where p.UserGUID == item.UserGUID
        //        //                             select p).SingleOrDefault());
        //        //        }
        //        //    }
        //        //}
        //        //else
        //        //{
        //        //    using (var dataContext = new WorkersInMotionContext())
        //        //    {

        //        //        globalUser = (from p in dataContext.GlobalUser
        //        //                      where p.UserGUID == UserGUID
        //        //                      select p).ToList();
        //        //        foreach (GlobalUser item in globalUser)
        //        //        {
        //        //            userProfile.Add((from p in dataContext.UserProfile
        //        //                             where p.UserGUID == item.UserGUID
        //        //                             select p).SingleOrDefault());
        //        //        }

        //        //    }
        //        //}
        //    }
        //    _getUsers.GlobalUser = globalUser;
        //    _getUsers.UserProfile = userProfile;
        //    return _getUsers;
        //}

        //public GetUsers GetClientUsers(string SessionID)
        //{
        //    GetUsers _getUsers = new GetUsers();
        //    using (var dataContext = new WorkersInMotionDB())
        //    {

        //        //Guid OrganizationGUID = new Guid((from p in dataContext.MasterLogin
        //        //                                  where p.SessionID == SessionID
        //        //                                  select p).SingleOrDefault().OrganizationGUID.ToString());
        //        //Guid UserGUID = new Guid((from p in dataContext.MasterLogin
        //        //                          where p.SessionID == SessionID
        //        //                          select p).SingleOrDefault().UserGUID.ToString());
        //        //_getUsers = GetUserFromClient(UserGUID, OrganizationGUID);
        //    }
        //    return _getUsers;
        //}

        public string GetUserID(string SessionID)
        {
            //using (var dataContext = new WorkersInMotionDB())
            //{
            //    return (from p in dataContext.MasterLogins
            //            where p.SessionID == SessionID
            //            select p).SingleOrDefault().UserGUID.ToString();
            //}

            SqlParameter[] Param = new SqlParameter[1];
            Param[0]       = new SqlParameter("@pSessionID", SqlDbType.NVarChar, -1);
            Param[0].Value = SessionID;
            MasterLogin mLogin = context.Database.SqlQuery <MasterLogin>("Select * from MasterLogins where SessionID=@pSessionID", Param).FirstOrDefault();

            if (mLogin != null)
            {
                return(mLogin.UserGUID.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 9
0
        private void OnAssignNewKeysConfirmMsg(AssignNewKeysConfirmMsg msg)
        {
            _logger.Info("assign new keys confirmed --> assing new keys");
            MasterLogin login = _database.GetAll <MasterLogin>().FirstOrDefault();

            if (login != null)
            {
                _logger.Info("assign new keys");
                _cryptographyService.AssignNewKeys();

                login.PublicKey  = _cryptographyService.GetPublicKey();
                login.PrivateKey = _cryptographyService.GetPrivateKeyAsXml();

                _logger.Info("update login with new keys");
                _database.Update(login);
                _logger.Info("login with new keys updated");

                _messenger.Send(new AssignNewKeysSuccsessMsg());
            }
            else
            {
                _logger.Error("login is null!");
            }
        }
Ejemplo n.º 10
0
        private void logInButton_Click(object sender, EventArgs e)
        {
            // Create a newQuery Object to store the data from the Username and Password text boxes
            MasterLogin newQuery = new MasterLogin();

            newQuery.Username = userNameTextBox.Text;
            newQuery.Password = passwordTextBox.Text;

            // Starting the try/catch method
            try
            {
                // takes newQuery and checks the DB to see if there is a match. If there is a match, open MainPasswordForm
                int user_login_id = connection.QueryFirst <int>("SELECT User_Login_ID FROM User_Login where Username = @Username AND Password = @Password", newQuery);

                MainPasswordForm newForm = new MainPasswordForm(user_login_id);
                newForm.Show();
                this.Hide();
            }
            catch (Exception)
            {
                // If no match is found, show this message box.
                MessageBox.Show("The username and password combination is wrong!");
            }
        }
Ejemplo n.º 11
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (ContentPlaceHolder1.Page.GetType().BaseType.Name == "Games")
     {
         Button Games = (Button)MasterLogin.FindControl("Games");
         Games.Text        = "user";
         Games.PostBackUrl = "~/default.aspx";
     }
     if (Membership.GetUser() != null)
     {
         // user is logged in
         Label username = (Label)MasterLogin.FindControl("WelcomeLabel");
         username.Text = " " + Membership.GetUser().UserName;
         if (ContentPlaceHolder1.Page.GetType().BaseType.Name == "admin")
         {
             if (Roles.GetRolesForUser().Contains("admins"))
             {
                 Button adminpage = (Button)MasterLogin.FindControl("AdminButton");
                 adminpage.Text        = "user";
                 adminpage.PostBackUrl = "~/default.aspx";
             }
         }
     }
 }
Ejemplo n.º 12
0
        private void DoLogin(object parameter)
        {
            UIServices.SetBusyState();
            _logger.Info("reset error msg");
            ErrorMsg = string.Empty;

            _logger.Info("starting with login process");

            if (!string.IsNullOrEmpty(_login) && _login.Length >= 6)
            {
                var values      = (object[])parameter;
                var passwordBox = values[0] as PasswordBox;

                if (passwordBox != null)
                {
                    _logger.Info("password parameter is not null");

                    string password = passwordBox.Password;

                    if (!string.IsNullOrEmpty(password))
                    {
                        _logger.Info("password is not null or empty");

                        _logger.Info("check for exsisting login");
                        var database = Container.Resolve <IDataAccessLayer>();
                        List <MasterLogin> logins = database.GetAll <MasterLogin>();

                        if (logins.Count == 1)
                        {
                            var login = database.GetSingleByName <MasterLogin>(_login);

                            if (login != null)
                            {
                                _logger.Info("login do exsits");
                                byte[] hashedPassword = _cryptographyService.HashPassword(password, login.Salt);

                                _logger.Info("compare passwords...");
                                if (_cryptographyService.Compare(hashedPassword, login.Password))
                                {
                                    _logger.Info("...login verified.");

                                    OpenMainView(values);
                                }
                                else
                                {
                                    _logger.Error("...login failed.");
                                    ErrorMsg = "Login failed!";
                                }
                            }
                            else
                            {
                                _logger.Error("master login already exists");
                                ErrorMsg = "Master login already exists!";
                            }
                        }
                        else if (logins.Count == 0)
                        {
                            _logger.Info("login do not exsits");

                            byte[] salt           = _cryptographyService.GenerateSalt();
                            byte[] hashedPassword = _cryptographyService.HashPassword(password, salt);

                            _cryptographyService.AssignNewKeys();

                            var masterLogin = new MasterLogin
                            {
                                Name       = _login,
                                Password   = hashedPassword,
                                Salt       = salt,
                                PrivateKey = _cryptographyService.GetPrivateKeyAsXml(),
                                PublicKey  = _cryptographyService.GetPublicKey(),
                            };

                            database.Insert(masterLogin);

                            OpenMainView(values);
                        }
                    }
                    else
                    {
                        _logger.Error("password is null or empty!");
                        ErrorMsg = "Password is empty!";
                    }
                }
            }
            else
            {
                _logger.Error("login is null, empty or have less then 6 characters!");
                ErrorMsg = "Login have less then 6 characters!";
            }
        }
        private void LoginExecute(object parametar)
        {
            var passwordBox = parametar as PasswordBox;
            var password    = passwordBox.Password;

            try
            {
                if (MasterLogin.Login(username, password) == true)
                {
                    MessageBox.Show("Successful login");
                    MasterAdminView window = new MasterAdminView();
                    window.Show();
                    main.Close();
                }
                else if (MasterLogin.Login(username, password) == false)
                {
                    ClinicUser user = service.LoginUser(username, password);
                    if (user != null)
                    {
                        if (user.RoleId == 1)
                        {
                            if (service.FindeInstitutionByUser(user.ClinicUserId) == false)
                            {
                                MessageBox.Show("Successful login");
                                AddInstitutionView window = new AddInstitutionView(user, new Institution(), false);
                                window.Show();
                                main.Close();
                            }
                            else
                            {
                                MessageBox.Show("Successful login");
                                AdministratorView window = new AdministratorView(user);
                                window.Show();
                                main.Close();
                            }
                        }
                        else if (user.RoleId == 2)
                        {
                            MessageBox.Show("Successful login maintainanc");
                        }
                        else if (user.RoleId == 3)
                        {
                            MessageBox.Show("Successful login manager");
                        }
                        else if (user.RoleId == 4)
                        {
                            MessageBox.Show("Successful login doctor");
                        }
                        else if (user.RoleId == 5)
                        {
                            MessageBox.Show("Successful login patient");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong user or password credentials");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 14
0
        public LoginResponse Login(LoginRequest pLoginRequest)
        {
            LoginResponse   loginResponse = new LoginResponse();
            IUserRepository _IUserRepository;

            _IUserRepository = new UserRepository(new WorkersInMotionDB());
            string UpdatedSessionID = string.Empty;

            Logger.Debug("Inside UserLogin");
            LoginResponse lResponse = new LoginResponse();

            try
            {
                MasterLogin masterlogin = new MasterLogin();
                var         aspuser     = _IUserRepository.UserLogin(pLoginRequest.UserName, _IUserRepository.EncodeTo64(pLoginRequest.Password));
                if (aspuser != null)
                {
                    Logger.Debug("Inside Role");
                    AspNetRole asprole = _IUserRepository.GetRole(aspuser.Role_Id);
                    switch (asprole.UserType)
                    {
                    case "WIM_A":
                    case "ENT_A":
                    case "ENT_OM":
                    case "ENT_U_RM":
                    case "ENT_U_TM":
                        lResponse.Role = 1;
                        break;

                    case "ENT_U":
                        lResponse.Role = 2;
                        break;

                    case "IND_C":
                        lResponse.Role = 3;
                        break;

                    default:
                        break;
                    }

                    UserDevice         userDevice   = new UserDevice();
                    List <MasterLogin> masterlogins = new List <MasterLogin>();
                    MasterLogin        lMasterLogin = new MasterLogin();
                    lMasterLogin.UserGUID  = aspuser.UserGUID;
                    lMasterLogin.LoginType = (short)pLoginRequest.LoginType;
                    masterlogins           = _IUserRepository.GetMasterLogin(lMasterLogin);
                    if (masterlogins != null && masterlogins.Count > 0)
                    {
                        #region masterlogins record available
                        masterlogin = masterlogins[0]; // Alok need to be fixed
                        // Update the Master Login
                        masterlogin.ExpiryTime = DateTime.UtcNow.AddYears(10);
                        Logger.Debug("Updating MasterLogin Record");
                        UpdatedSessionID = _IUserRepository.UpdateMasterLogin(masterlogin);
                        if (!string.IsNullOrEmpty(UpdatedSessionID))
                        {
                            #region UpdatedSessionID is not null

                            Logger.Debug("Updated Session ID: " + UpdatedSessionID);
                            lResponse.SessionID = UpdatedSessionID;
                            lResponse.UserGUID  = aspuser.UserGUID.ToString();

                            Logger.Debug("Inside MasterLogin");
                            userDevice.LoginGUID = masterlogin.LoginGUID;
                            userDevice.DeviceID  = pLoginRequest.DeviceInfo.deviceid;
                            List <UserDevice> lUserDevices = _IUserRepository.GetUserDevice(userDevice);
                            if (lUserDevices != null && lUserDevices.Count > 0)
                            {
                                // Delete the user device record
                                userDevice = lUserDevices[0]; // Need to modify Alok
                                int deviceresult = _IUserRepository.DeleteUserDevices(userDevice.UserDevicesGUID);
                                //int deviceresult = _IUserRepository.Save();
                                if (deviceresult <= 0)
                                {
                                    lResponse = null;
                                    return(lResponse);
                                }
                            }
                            // Insert the User Device info
                            if (CreateUserDevice(masterlogin, pLoginRequest) > 0)
                            {
                                if (!string.IsNullOrEmpty(lResponse.SessionID) && !string.IsNullOrEmpty(lResponse.UserGUID))
                                {
                                    DownloadUsers lDownloadUsers = DownloadUsers(lResponse.SessionID, new Guid(lResponse.UserGUID));
                                    if (lDownloadUsers != null && lDownloadUsers.UserRecords.Count > 0)
                                    {
                                        lResponse.UserRecord = lDownloadUsers.UserRecords[0];
                                    }
                                    else
                                    {
                                        lResponse.UserRecord = null;
                                    }
                                }
                                Logger.Debug("UserDevice record created for updated Session ID: " + UpdatedSessionID);
                            }
                            #endregion
                        }
                        else
                        {
                            #region UpdatedSessionID is NULL
                            Logger.Error("Unable to generate Session ID");
                            lResponse = null;
                            return(lResponse);

                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        #region masterlogins record not available
                        Logger.Debug("Creating MasterLogin Record");
                        lMasterLogin.ExpiryTime = DateTime.UtcNow.AddYears(10);
                        if (CreateMasterLogin(lMasterLogin) > 0)
                        {
                            Logger.Debug("New Session ID: " + lMasterLogin.SessionID);
                            lResponse.SessionID = lMasterLogin.SessionID;
                            lResponse.UserGUID  = lMasterLogin.UserGUID.ToString();
                            Logger.Debug("Inside UserDevice create");

                            if (CreateUserDevice(masterlogin, pLoginRequest) > 0)
                            {
                                if (!string.IsNullOrEmpty(lResponse.SessionID) && !string.IsNullOrEmpty(lResponse.UserGUID))
                                {
                                    DownloadUsers lDownloadUsers = DownloadUsers(lResponse.SessionID, new Guid(lResponse.UserGUID));
                                    if (lDownloadUsers != null && lDownloadUsers.UserRecords.Count > 0)
                                    {
                                        lResponse.UserRecord = lDownloadUsers.UserRecords[0];
                                    }
                                    else
                                    {
                                        lResponse.UserRecord = null;
                                    }
                                }
                                Logger.Debug("UserDevice record created for new Session ID: " + lMasterLogin.SessionID);
                            }
                            else
                            {
                                Logger.Error("Unable to craete UserDevice record for new Session ID: " + lMasterLogin.SessionID);
                                lResponse = null;
                            }
                        }
                        else
                        {
                            Logger.Error("Unable to craete MasterLogin record");
                            lResponse = null;
                        }
                        #endregion
                    }
                }
                else
                {
                    Logger.Error("Unable to find user record in  AspUser");
                    lResponse = null;
                }
                return(lResponse);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                lResponse = null;
                //lResponse.SessionID = new WorkersInMotionDB().Database.Connection.ConnectionString + " Exception: " + ex.Message;
                return(lResponse);
            }
        }
        private void Confirm(object obj)
        {
            UIServices.SetBusyState();
            _logger.Info("password change confirmed");

            _logger.Info("parsing parameters");
            var parameters      = (object[])obj;
            var oldPasswordBox  = parameters[0] as PasswordBox;
            var newPasswordBox  = parameters[1] as PasswordBox;
            var newPassword2Box = parameters[2] as PasswordBox;

            if (oldPasswordBox != null && newPasswordBox != null && newPassword2Box != null)
            {
                _logger.Info("parameters not null");

                _logger.Info("get login data");
                MasterLogin login = _database.GetAll <MasterLogin>().First();

                _logger.Info("hash entered password");
                byte[] hashedPassword = _cryptographyService.HashPassword(oldPasswordBox.Password, login.Salt);

                _logger.Info("compare entered and stored passwords");
                if (_cryptographyService.Compare(hashedPassword, login.Password))
                {
                    _logger.Info("password are correct");

                    string newPassword1 = newPasswordBox.Password;
                    string newPassword2 = newPassword2Box.Password;

                    _logger.Info("compare new passwords");
                    if (newPassword1 == newPassword2)
                    {
                        _logger.Info("hash new password");
                        byte[] newSalt           = _cryptographyService.GenerateSalt();
                        byte[] newHashedPassword = _cryptographyService.HashPassword(newPassword1, newSalt);

                        login.Salt     = newSalt;
                        login.Password = newHashedPassword;

                        _logger.Info("save changes");
                        _database.Update(login);
                        _logger.Info("changes are saved");

                        InformUserAndClose(parameters);
                    }
                    else
                    {
                        _logger.Error("new passwords do not match");
                        ErrorMsg = "Passwords do not match!";
                    }
                }
                else
                {
                    _logger.Error("current password is wrong!");
                    ErrorMsg = "Old Password is wrong!";
                }
            }
            else
            {
                _logger.Error("parameters are null!");
                ErrorMsg = "Something went wrong, pleas try again.";
            }
        }