Skip to content

Instantly share code, notes, and snippets.

View DiegoQueiroz's full-sized avatar

Diego Queiroz DiegoQueiroz

  • São Paulo, SP, Brazil
View GitHub Profile
uses
Windows, SysUtils;
function GeraDigitosAleatorios(tamanho: Integer): String;
type
TBCryptGenRandom = function(hAlgorithm: THandle; pbBuffer: PUCHAR;
cbBuffer, dwFlags: ULONG): ULONG; stdcall;
const
bcryptdll = 'bcrypt.dll';
STATUS_SUCCESS = $00000000;
Attribute VB_Name = "GeraDigitosAleatorios"
Option Explicit
Private Declare Function BCryptGenRandom Lib "bcrypt.dll" (ByVal hAlgorithm As Long, ByRef pbBuffer As Long, ByVal cbBuffer As Long, ByVal dwFlags As Long) As Long
Const BCRYPT_USE_SYSTEM_PREFERRED_RNG = &H2
Const STATUS_SUCCESS = &H0
Public Function GeraDigitosAleatorios(ByVal tamanho As Integer) As String
Const ERRO_GERACAO_SEQUENCIA_NUMERO = vbObjectError + 1
Imports System.Text
Imports System.Security.Cryptography
Module VBModule
Sub Main()
Console.WriteLine(GeraDigitosAleatorios(8))
End Sub
Function GeraDigitosAleatorios(ByVal tamanho As Integer) As String
@DiegoQueiroz
DiegoQueiroz / GeraDigitosAleatorios.cs
Last active July 22, 2020 21:17
Arruma identação
using System;
using System.Text;
using System.Security.Cryptography;
public class Program {
public static void Main() {
Console.WriteLine(GeraDigitosAleatorios(8));
}
SELECT
RIGHT(ABS(CAST(CRYPT_GEN_RANDOM(str_size) AS BIGINT)), str_size) crypto_rand
FROM
(select 8 str_size) var; -- "8" é o tamanho da string a ser gerada
-- Para executar esse código é necessário ter acesso ao pacote DBMS_CRYPTO
-- GRANT EXECUTE ON SYS.DBMS_CRYPTO TO <seu_usuario>;
SELECT
LPAD(DBMS_CRYPTO.RANDOMNUMBER, str_size, '0') crypto_rand
FROM
(SELECT 8 str_size FROM dual); -- "8" é o tamanho da string a ser gerada
@DiegoQueiroz
DiegoQueiroz / GeraDigitosAleatorios.java
Last active July 22, 2020 20:30
Sequência de dígitos aleatórios em Java, utilizando SecureRandom
import java.security.SecureRandom;
public class Main {
public static void main(String[] args) throws Exception {
System.out.println(GeraDigitosAleatorios(8));
}
@DiegoQueiroz
DiegoQueiroz / query_activedirectory.py
Last active October 18, 2023 10:43
Python-LDAP Query Active Directory Example (with paged results to prevent ldap.SIZELIMIT_EXCEEDED exception)
# -*- coding: utf-8 -*-
# requires python-ldap (usually pip install python-ldap)
# But this package requires OpenLDAP libraries, so it is a pain to install it on Windows.
# So, if you're on Windows, I recomment to use pre-compiled binaries with this command (virtualenv supported):
# pip install https://download.lfd.uci.edu/pythonlibs/h2ufg7oq/python_ldap-3.1.0-cp37-cp37m-win_amd64.whl
import ldap
from ldap.controls import SimplePagedResultsControl
@DiegoQueiroz
DiegoQueiroz / RunMe.py
Last active May 17, 2018 16:50
Run a process and prepare it to terminate when it becomes orphan
# -*- coding: utf-8 -*-
# RunMe.Py
# 2018 - Diego Queiroz
#
# Usage:
# Linux : python /path/to/RunMe.py /path/to/your/your_script.sh
# Windows: C:\path\to\python.exe C:\path\to\RunMe.py C:\path\to\your_script.bat
#
import atexit
@DiegoQueiroz
DiegoQueiroz / nubank_password.sh
Last active February 7, 2017 20:12
Baixar a senha do cartão Nubank.com.br (formato JSON)
#!/bin/bash
# Baixa a senha do cartão Nubank
# Uso:
# ./nubank_password.sh <cpf> <senha>
cpf=$1
senha=$2
if [ "$cpf" == "" ]; then
read -p "Digite o CPF: " cpf