Posts

Showing posts with the label Python Sample Codes for Intrusion Detection and Prevention

Python Sample Codes for Intrusion Detections and Preventions

1. Secure Password Generation:  Use 'secrets' module. import string import secrets alphabet = string.ascii_letters + string.digits password = ''.join(secrets.choice(alphabet) for i in range(16)) print(password) 2. Hashing Passwords: Use 'hashlib' module hashing passwords with SHA-256, SHA-512, etc. Example 1 : import hashlib password = "mysecret" hash_object = hashlib.sha256(password.encode()) hashed_password = hash_object.hexdigest() print(hashed_password) Example 2: Use bcrypt library hashing password and store the hashed password in a MySQL database. import bcrypt import mysql.connector # Connect to MySQL database db = mysql.connector.connect(   host="localhost",   user="yourusername",   password="yourpassword",   database="yourdatabase" ) # Generate a salt for password hashing salt = bcrypt.gensalt() # Get password from user input password = input("Ent...