File size: 1,842 Bytes
bdd445e
 
 
3e9865c
bdd445e
3e9865c
 
 
bdd445e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e9865c
 
 
 
 
bdd445e
 
 
 
 
 
 
 
 
 
 
 
 
3e9865c
bdd445e
3e9865c
bdd445e
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import re
import math
import whois
import datetime

# -------------------------
# URL Analyzer
# -------------------------
def analyze_url(url):
    score = 0
    reasons = []

    if not url.startswith("https"):
        score += 1
        reasons.append("URL is not HTTPS secure")

    if re.search(r"\d+\.\d+\.\d+\.\d+", url):
        score += 1
        reasons.append("IP address detected in URL")

    suspicious_words = ["login", "verify", "bank", "secure", "update"]
    for word in suspicious_words:
        if word in url.lower():
            score += 1
            reasons.append(f"Suspicious word detected: {word}")

    # Domain age check
    try:
        domain_info = whois.whois(url)
        creation_date = domain_info.creation_date
        if isinstance(creation_date, list):
            creation_date = creation_date[0]
        if creation_date:
            age_days = (datetime.datetime.now() - creation_date).days
            if age_days < 180:
                score += 1
                reasons.append("Newly registered domain (<6 months)")
    except:
        pass

    if score == 0:
        return "✅ Safe URL"
    elif score == 1:
        return "⚠️ Slightly Suspicious\n" + "\n".join(reasons)
    else:
        return "🚨 High Risk URL\n" + "\n".join(reasons)

# -------------------------
# Password Strength
# -------------------------
def password_strength(password):
    length = len(password)
    entropy = length * math.log2(94)

    strength = "Weak"
    if length >= 8 and re.search(r"[A-Z]", password) and re.search(r"[0-9]", password):
        strength = "Medium"
    if length >= 12 and re.search(r"[!@#$%^&*]", password):
        strength = "Strong"

    crack_time = round(2 ** (entropy / 10))
    return f"Strength: {strength}\nEntropy: {round(entropy,2)}\nEstimated Crack Attempts: {crack_time}"