TestCardPro / app.py
waqasbm's picture
Create app.py
847eab0 verified
import streamlit as st
import random
from faker import Faker
from datetime import datetime, timedelta
fake = Faker()
# ---------------- UI CONFIG ----------------
st.set_page_config(
page_title="Credit Card Generator",
layout="centered",
initial_sidebar_state="collapsed"
)
# ---- Dark Mode Styling ----
st.markdown("""
<style>
body {
background-color: #0e1117;
color: #ffffff;
}
.stButton>button {
background-color: #4CAF50;
color: white;
border-radius: 8px;
height: 3em;
width: 100%;
}
.card-box {
background: linear-gradient(135deg, #1f2937, #111827);
padding: 20px;
border-radius: 12px;
color: white;
font-family: monospace;
}
.copy-btn {
margin-top: 10px;
}
</style>
""", unsafe_allow_html=True)
st.title("💳 Credit Card Generator")
st.caption("Generate **test credit card details** for development and QA use only.")
# ---------------- INPUT ----------------
card_type = st.selectbox("Select Card Type", ["VISA", "MASTERCARD"])
generate = st.button("Generate Card")
# ---------------- CORE LOGIC ----------------
def luhn_generate(prefix, length):
number = prefix
while len(number) < length - 1:
number += str(random.randint(0, 9))
digits = [int(d) for d in number]
for i in range(len(digits) - 1, -1, -2):
digits[i] *= 2
if digits[i] > 9:
digits[i] -= 9
checksum = (10 - (sum(digits) % 10)) % 10
return number + str(checksum)
def format_card(number):
return " ".join([number[i:i+4] for i in range(0, len(number), 4)])
def generate_expiry():
future_date = datetime.now() + timedelta(days=random.randint(365, 1825))
return future_date.strftime("%m/%y")
def generate_cvv():
return str(random.randint(100, 999))
def detect_country(bin_prefix):
bin_map = {
"4": "USA / International (VISA)",
"51": "USA (MasterCard)",
"52": "Canada",
"53": "UK",
"54": "Germany",
"55": "France"
}
return bin_map.get(bin_prefix[:2], "Unknown")
def generate_card(card_type):
if card_type == "VISA":
prefix = "4"
length = 16
else:
prefix = str(random.choice(range(51, 56)))
length = 16
number = luhn_generate(prefix, length)
return {
"number": number,
"formatted": format_card(number),
"name": fake.name(),
"zip": fake.zipcode(),
"expiry": generate_expiry(),
"cvv": generate_cvv(),
"country": detect_country(prefix)
}
# ---------------- OUTPUT ----------------
if generate:
card = generate_card(card_type)
st.success("Card Generated")
st.markdown(f"""
<div class="card-box">
<h3>{card_type}</h3>
<p style="font-size:20px;">{card['formatted']}</p>
<p>{card['name']}</p>
<p>EXP: {card['expiry']} | CVV: {card['cvv']}</p>
</div>
""", unsafe_allow_html=True)
st.write(f"**ZIP Code:** {card['zip']}")
st.write(f"**Country (BIN):** {card['country']}")
# -------- Copy Buttons --------
st.subheader("Copy Details")
st.code(card["number"], language="text")
st.code(card["formatted"], language="text")
st.code(card["cvv"], language="text")
st.info("⚠️ These are fake/generated details for testing only. Not usable for real transactions.")