Password Hashing Function with SHA-256

  • Share this:

Code introduction


This function takes a password string as input, uses the SHA-256 algorithm to hash it, and returns the hashed string.


Technology Stack : hashlib

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
import os
import sys
import time
import re
import hashlib
import json

def hash_password(password):
    """对密码进行哈希处理

    Args:
        password (str): 用户输入的密码

    Returns:
        str: 加密后的密码
    """
    hash_object = hashlib.sha256(password.encode())
    return hash_object.hexdigest()                
              
Tags: