コード例 #1
0
        public async Task <IActionResult> CheckEmail([FromBody] TSEmail tsEmail)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "Check Email", MethodBase.GetCurrentMethod());


            GlobalFunctions.CmdDecryptEntityAsymm(tsEmail);


            TSUserEntity user = TS.FindUser(tsEmail.To, true, "Email").Result;

            TSEmail result = new TSEmail
            {
                To            = string.Empty,
                OperationCode = 0
            };

            if (user is null)
            {
                result.Result = "OK";
            }
            else
            {
                result.Result = "Email already exists";
            }

            return(Ok(result));
        }
コード例 #2
0
        public async Task <IActionResult> PassRecovery([FromBody] TSEmail tsEmail)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "Pass Recovery", MethodBase.GetCurrentMethod());

            GlobalFunctions.CmdDecryptEntityAsymm(tsEmail);


            EmailOperationsEnum currOperationCode = (EmailOperationsEnum)tsEmail.OperationCode;


            string newPass = GlobalFunctions.GetSalt();


            TSUserEntity tsUserEntity = TS.FindUser(tsEmail.To, false, string.Empty).Result;

            if (tsUserEntity != null)
            {
                tsUserEntity.Salt           = GlobalFunctions.GetSalt();
                tsUserEntity.HashedPassword = GlobalFunctions.CmdHashPasswordBytes(newPass, tsUserEntity.Salt);

                bool b = TS.UpdateUserEntity(tsUserEntity).Result;

                if (b)
                {
                    tsEmail.To = tsUserEntity.Email;
                    TSEmail result = await GlobalFunctions.SendEmail(tsEmail, string.Empty, newPass);

                    result.To            = string.Empty;
                    result.OperationCode = 0;
                    return(Ok(result));
                }
                else
                {
                    return(Ok("Error: Could not recover user password"));
                }
            }
            else
            {
                return(Ok("Error: User not found"));
            }
        }
コード例 #3
0
        //public Startup(IConfiguration configuration, ILogger<Startup> logger)
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            //_logger = logger;

            //_logger.LogInformation("Added TodoRepository to services");
            GlobalFunctions.CmdReadEncryptedSettings();

            TS = new TableStorage();
            bool b = TS.EnuserTables().Result;

            TSUserEntity demoUser = TS.FindUser("DemoUser", false, string.Empty).Result;

            if (demoUser is null)
            {
                TSUser newUser = new TSUser()
                {
                    Email      = "*****@*****.**",
                    Password   = "******",
                    FullName   = "Demo User",
                    UserName   = "******",
                    UserID     = TS.GetNewID("AllUsers", "LastUserID", true).Result,
                    CreateDate = DateTime.Now,
                };

                DemoUserID = newUser.UserID;
                b          = TS.AddUser(newUser).Result;
            }
            else
            {
                DemoUserID = demoUser.PartitionKey;
            }

            b = TS.AddActivityLog("AllUser", "Server started", MethodBase.GetCurrentMethod()).Result;


            _timerUserUpdater = new Timer(DoWorkUserUpdater, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10));
            _timerReminder    = new Timer(DoWorkReminder, null, TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(1));
        }
コード例 #4
0
        private Task <ClaimsIdentity> GetIdentity(string Par_Username,
                                                  string Par_Password,
                                                  string Par_IPAddress,
                                                  string Par_MachineID,
                                                  WebApiUserTypesEnum ParWebApiUserType,
                                                  out string Par_Out_Result,
                                                  out string Par_Out_UserRole)
        {
            Par_Out_Result   = string.Empty;
            Par_Out_UserRole = string.Empty;

            try
            {
                switch (ParWebApiUserType)
                {
                case WebApiUserTypesEnum.NotAuthorized:
                    Par_Out_UserRole = "NotAutorizedUser";
                    if (Par_Username.Equals(GlobalData.NotAuthorizedUserName) && Par_Password.Equals(GlobalData.NotAuthorizedUserPass))
                    {
                        Par_Out_Result = GlobalFunctions.CmdAsymmetricEncrypt("-745" + GlobalFunctions.GetRandomAlphaNumeric(10));
                        return(Task.FromResult(new ClaimsIdentity(new System.Security.Principal.GenericIdentity(Par_Username, "Token"), new Claim[] { })));
                    }
                    else
                    {
                        Par_Out_Result = "Invalid NotAutorizedUser UserName or Password";
                    }

                    break;

                case WebApiUserTypesEnum.Authorized:
                    Par_Out_UserRole = "AutorizedUser";
                    TSUserEntity tsUserEntity = TS.FindUser(Par_Username, false, string.Empty).Result;
                    if (tsUserEntity != null)
                    {
                        if (GlobalFunctions.CompareHash(Par_Password, tsUserEntity))
                        {
                            Par_Out_Result = GlobalFunctions.CmdAsymmetricEncrypt(tsUserEntity.PartitionKey + GlobalFunctions.GetRandomAlphaNumeric(10));
                            return(Task.FromResult(new ClaimsIdentity(new System.Security.Principal.GenericIdentity(Par_Username, "Token"), new Claim[] { })));
                        }
                        else
                        {
                            Par_Out_Result = "Invalid AutorizedUser Password";
                        }
                    }
                    else
                    {
                        Par_Out_Result = "Invalid AutorizedUser Name";
                    }

                    break;

                case WebApiUserTypesEnum.Admin:
                    Par_Out_UserRole = "Admin";
                    if (Par_IPAddress.Equals(GlobalData.AdminIPAddress))
                    {
                        if (Par_MachineID.Equals(GlobalData.AdminMachineID))
                        {
                            if (Par_Username.Equals(GlobalData.AdminUserName) && Par_Password.Equals(GlobalData.AdminUserPass))
                            {
                                Par_Out_Result = GlobalFunctions.CmdAsymmetricEncrypt("-1" + GlobalFunctions.GetRandomAlphaNumeric(10));
                                return(Task.FromResult(new ClaimsIdentity(new System.Security.Principal.GenericIdentity(Par_Username, "Token"), new Claim[] { })));
                            }
                            else
                            {
                                Par_Out_Result = "Invalid Admin UserName or Password";
                            }
                        }
                        else
                        {
                            Par_Out_Result = "Invalid Admin MachineID";
                        }
                    }
                    else
                    {
                        Par_Out_Result = "Invalid Admin IPAddress";
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                bool b = TS.AddErrorLog("AllUsers", ex.Message, MethodBase.GetCurrentMethod()).Result;
            }

            // Credentials are invalid, or account doesn't exist
            return(Task.FromResult <ClaimsIdentity>(null));
        }
コード例 #5
0
        //public static string Get_Caller_Name([CallerMemberName]string name = "")
        //{
        //    return name;
        //}

        public static bool CompareHash(string Par_password, TSUserEntity currTSUserEntity)
        {
            return(StructuralComparisons.StructuralEqualityComparer.Equals(CmdHashPasswordBytes(Par_password, currTSUserEntity.Salt), currTSUserEntity.HashedPassword));
        }