コード例 #1
0
ファイル: DBLogin.cs プロジェクト: DerekZiemba/UniEvents
        public static async Task <DBLogin> LoginUserNameAsync(Factory ctx, string username)
        {
            var dbLogin = new DBLogin();

            dbLogin.UserName = username;
            (dbLogin.APIKeyHash, dbLogin.APIKey) = HashUtils.CreateAPIKey256(dbLogin.UserName);
            if (await SP_Account_LoginAsync(ctx, dbLogin).ConfigureAwait(false))
            {
                return(dbLogin);
            }
            return(null);
        }
コード例 #2
0
ファイル: DBLogin.cs プロジェクト: DerekZiemba/UniEvents
        private static async Task <bool> SP_Account_LoginAsync(Factory ctx, DBLogin model)
        {
            using (SqlConnection conn = new SqlConnection(ctx.Config.dbUniHangoutsWrite))
                using (SqlCommand cmd = new SqlCommand("[dbo].[sp_Account_Login]", conn)
                {
                    CommandType = CommandType.StoredProcedure
                }) {
                    cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(UserName), model.UserName);
                    cmd.AddParam(ParameterDirection.Input, SqlDbType.VarChar, nameof(APIKey), model.APIKey);
                    cmd.AddParam(ParameterDirection.Input, SqlDbType.Binary, nameof(APIKeyHash), model.APIKeyHash);
                    SqlParameter date = cmd.AddParam(ParameterDirection.Output, SqlDbType.DateTime, nameof(LoginDate), model.LoginDate);

                    int rowsAffected = await cmd.ExecuteProcedureAsync().ConfigureAwait(false);

                    model.LoginDate = (DateTime)date.Value;

                    return(model.LoginDate > DateTime.UtcNow.AddMinutes(-1) && model.LoginDate < DateTime.UtcNow.AddMinutes(1));
                }
        }