Towards Dev

A publication for sharing projects, ideas, codes, and new theories.

Follow publication

Member-only story

Revolutionizing Password Strength Evaluation with OpenAI: A New Open Source Project — PSC

Bill WANG
Towards Dev
Published in
4 min readFeb 2, 2024

--

Have you ever been tasked with reviewing the strength of password and felt lost in the sea of open-source tools on GitHub? I recently faced a similar challenge when my manager assigned me the job of assessing password strength. Navigating through various GitHub repositories, I discovered that most existing tools rely heavily on code and offer limited features for evaluating password robustness. Moreover, building and maintaining a huge password library seemed like an overwhelming task.

I thought, why not use OpenAI to simplify things? I tested it with a basic prompt:

Check if the password 'Pass!234' is strong, or weak. Please only answer 'strong', 'weak'

In less than a second, I got the answer — weak. That’s when I realized I didn’t need to start from scratch.

Inspired by this, I delved into the OpenAI API documentation (https://platform.openai.com/docs/api-reference/chat/create) and quickly put the idea together with the golang codes.

package main

import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"

"github.com/joho/godotenv"
)

// checkPasswordStrength sends a request to OpenAI API to check the strength of a password
func checkPasswordStrength(apiKey, password string) (string, error) {
apiEndpoint := "https://api.openai.com/v1/chat/completions"

// Prepare the OpenAI API request payload
input := fmt.Sprintf("Check if the password '%s' is strong, or weak. Please only answer 'strong', 'weak'", password)
payload := map[string]interface{}{
"messages": []map[string]interface{}{
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": input},
},
"model": "gpt-3.5-turbo",
"max_tokens": 50,
}

payloadBytes, err := json.Marshal(payload)
if err != nil {
return "", err
}

// Make the OpenAI API request
req, err := http.NewRequest("POST", apiEndpoint, bytes.NewBuffer(payloadBytes))
if err != nil {
return "", err
}

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+apiKey)

client…

--

--

Published in Towards Dev

A publication for sharing projects, ideas, codes, and new theories.

No responses yet

Write a response