Must Have Python Script to Find Hardcoded Credentials FAST!

Publié le: 11 juillet 2024
sur la chaîne: PythonTrailBlazer
66
3

In this video you will learn how to automatically find hardcoded usernames and passwords in your Python files using a simple yet effective script.

This video walks you through a Python function that scans a folder, searches each file for hardcoded credentials, and prints the file name and line number where these credentials are found. It's a useful tool for ensuring your code is secure and free from hardcoded sensitive information.

Below are the Key Points Covered in this video:

Introduction to the problem of hardcoded credentials
Step-by-step guide to writing a Python script for detecting hardcoded usernames and passwords
Explanation of the script logic and how it works
Example usage and expected output
Best practices for keeping your code secure

Script Code used:
You can find the complete script used in this video below:

import os
def find_hardcoded_credentials(folder_name):
keywords = ['username', 'password', 'usr', 'pwd']

Walk through all files in the given folder
for root, _, files in os.walk(folder_name):
for file_name in files:
file_path = os.path.join(root, file_name)

Only process Python files
if file_path.endswith('.py'):
with open(file_path, 'r', encoding='utf-8') as file:
for line_number, line in enumerate(file, start=1):
for keyword in keywords:
if keyword in line and ('=' in line):
Check if the keyword is followed by an assignment to a string
parts = line.split('=')
if len(parts) == 2 and ('"' in parts[1] or "'" in parts[1]):
print(f"Found in {file_path} at line {line_number}: {line.strip()}")

Usage example
if _name_ == "__main__":
folder_name = r"C:\find_hardcoded_credentials" # Replace with your folder path
find_hardcoded_credentials(folder_name)

How to Find Hardcoded Credentials in Python Files - Python Automation Script
Protect Your Code by Finding Hardcoded Credentials in Python Files

#Python #Programming #Automation #CyberSecurity #PythonScript #CodeReview #LearnPython #TechTutorial #PythonAutomation #SecureCoding #PythonDev #PythonProgramming

Don't forget to like, comment, and subscribe for more Python tips and tutorials!

🔔 Subscribe to Python Trailblazer:    / @pythontrailblazer  


Sur cette page du site, vous pouvez voir la vidéo en ligne Must Have Python Script to Find Hardcoded Credentials FAST! durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur PythonTrailBlazer 11 juillet 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 66 fois et il a aimé 3 téléspectateurs. Bon visionnage!