目錄
Features
Usage
Under development
License
首頁 後端開發 Golang 用 Go 建構密碼管理器

用 Go 建構密碼管理器

Sep 18, 2024 pm 08:17 PM

身為軟體開發人員,我一直對安全性和可用性的交集著迷。最近,我決定開始一個令人興奮的專案:使用 Go 建立一個命令列密碼管理器。我想與您分享這段旅程的開始,從第一次提交開始。

創世記

2023 年 11 月 27 日,我對我的專案進行了初步提交,我將其命名為「dost」(印地語中的朋友,反映了它作為密碼管理的有用伴侶的角色)。這第一步雖然很小,但卻為我希望成為一個強大且用戶友好的工具奠定了基礎。

靈感與願景

Building a Password Manager in Go

在開始這個專案時,我從流行的命令列密碼管理器 pass 中汲取了靈感。 pass 的簡單性和有效性引起了我的注意,我決定使用它的 API 作為在 Go 中建立我自己的密碼管理器的藍圖。

深入研究 pass 的原始碼是令人大開眼界的經驗。我很有興趣地發現這項廣泛使用的工具的全部功能都封裝在一個綜合的 Bash 腳本中。這種優雅的簡單性是我所欣賞的,並希望在我自己的專案中效仿,儘管使用了 Go 的優勢。

透過學習 pass,我對命令列密碼管理器的基本功能及其應提供的使用者體驗獲得了寶貴的見解。當我繼續開發「dost」時,我將牢記這些教訓,旨在創建一個將 pass 的簡單性與 Go 的效能和跨平台相容性優勢結合起來的工具。

這次探索不僅為要實現的功能提供了路線圖,而且增強了我對精心設計、專注的工具的力量的信念。我很高興看到這種靈感將如何影響「dost」在未來發展階段的演變。

第一個特點

最初的提交重點在於兩個核心功能:

  1. 密碼產生:我實作了一個基本的密碼產生器,讓使用者可以指定他們所需的密碼長度。此功能旨在創建適合各種安全要求的強隨機密碼。

  2. 剪貼簿整合:為了增強使用者體驗,我確保產生的密碼會自動複製到剪貼簿。這個雖小但至關重要的功能可以節省時間並降低轉錄錯誤的風險。

技術見解

讓我們深入探討第一次迭代的一些技術面:

  • Go 版本:該專案使用 Go 1.21.0 構建,充分利用了該語言的簡單性和高效性。
  • 外部相依性:我正在使用 github.com/atotto/clipboard 套件來無縫處理不同作業系統之間的剪貼簿操作。
  • 隨機生成:密碼生成利用 Go 的 crypto/rand 套件進行安全隨機數生成,這對於創建不可預測的強密碼至關重要。
  • 字符集:密碼產生器包括大小寫字母、數字和各種特殊字符,以確保複雜性。

程式碼片段

讓我們來看看實現的一些關鍵部分:

  1. 密碼產生功能:
func generatePassword(length int) (string, error) {
    const (
        uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
        digits           = "0123456789"
        specialChars     = "!@#$%^&*()-_=+[]{}|;:'\",.<>/?"
    )

    allChars := uppercaseLetters + lowercaseLetters + digits + specialChars

    var password string
    for i := 0; i < length; i++ {
        randomIndex, err := rand.Int(rand.Reader, big.NewInt(int64(len(allChars))))
        if err != nil {
            return "", err
        }
        password += string(allChars[randomIndex.Int64()])
    }

    return password, nil
}
登入後複製

此函數透過從預定義集中隨機選擇字元來建立密碼,確保大寫、小寫、數字和特殊字元的混合。

  1. 剪貼簿整合:
func writeToClipboard(text string) error {
    return clipboard.WriteAll(text)
}
登入後複製

這個簡單的函數利用剪貼簿包將產生的密碼寫入系統剪貼簿。

  1. 主要功能:
func main() {
    passwordLength := flag.Int("length", 12, "length of your password")
    flag.Parse()

    password, err1 := generatePassword(*passwordLength)
    if err1 != nil {
        fmt.Println("Error generating password:", err1)
        return
    }

    fmt.Println("Generated Password:", password)

    err2 := writeToClipboard(password)
    if err2 != nil {
        fmt.Println("Error writing to clipboard:", err2)
        os.Exit(1)
    }

    fmt.Println("Copied to clipboard! ✅\n")
}
登入後複製

主要功能將所有內容連結在一起。它使用Go的flag包來允許使用者指定密碼長度,產生密碼,並將其複製到剪貼簿。

命令列介面

如你在 main 函數中看到的,我使用 Go 的 flag 套件實作了一個簡單的 CLI。使用者可以使用 -length 標誌指定所需的密碼長度,如果未指定,則預設為 12 個字元。

展望未來

第一次提交只是一個開始。當我繼續開發這個密碼管理器時,我計劃添加以下功能:

  • Secure storage of passwords
  • Encryption of stored data
  • Search and retrieval functionalities
  • Password strength analysis

I'm excited about the journey ahead and the challenges it will bring. Building a password manager is not just about coding; it's about understanding security principles, user needs, and creating a tool that people can trust with their sensitive information.

Stay tuned for more updates as this project evolves. I'll be sharing my progress, challenges, and learnings along the way. If you're interested in following along or contributing, feel free to check out the project on GitHub.

Building a Password Manager in Go svemaraju / dost

dost command line password manager written in Go

dost

dost is a CLI password manager written in Go.

Inspired by (Pass)[https://www.passwordstore.org/]

Features

  • Generate random passwords of configurable length
  • Copy generated passwords to clipboard automatically
  • Skip using symbols

Usage

> go build -o dost main.go
登入後複製
Enter fullscreen mode Exit fullscreen mode

Generating password:

> ./dost generate email/vema@example.com
Generated Password: );XE,7-Dv?)Aa+&<{V-|pKuq5
登入後複製

Generating password with specified length (default is 25):

> ./dost generate email/vema@example.com 12
Generated Password: si<yJ=5/lEb3
登入後複製

Copy generated password to clipboard without printing:

> ./dost generate -c email/vema@example.com 
Copied to clipboard! ✅
登入後複製

Avoid symbols for generating passwords:

> ./dost generate -n email/vema@example.com 
Generated Password: E2UST}^{Ac[Fb&D|cD%;Eij>H
登入後複製

Under development

  • Insert a new password manually
  • Show an existing password
  • List all entries
  • Password storage
  • GPG Key based encryption

License

MIT




View on GitHub


以上是用 Go 建構密碼管理器的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1672
14
CakePHP 教程
1428
52
Laravel 教程
1332
25
PHP教程
1277
29
C# 教程
1256
24
Golang vs. Python:性能和可伸縮性 Golang vs. Python:性能和可伸縮性 Apr 19, 2025 am 12:18 AM

Golang在性能和可擴展性方面優於Python。 1)Golang的編譯型特性和高效並發模型使其在高並發場景下表現出色。 2)Python作為解釋型語言,執行速度較慢,但通過工具如Cython可優化性能。

Golang和C:並發與原始速度 Golang和C:並發與原始速度 Apr 21, 2025 am 12:16 AM

Golang在並發性上優於C ,而C 在原始速度上優於Golang。 1)Golang通過goroutine和channel實現高效並發,適合處理大量並發任務。 2)C 通過編譯器優化和標準庫,提供接近硬件的高性能,適合需要極致優化的應用。

開始GO:初學者指南 開始GO:初學者指南 Apr 26, 2025 am 12:21 AM

goisidealforbeginnersandsubableforforcloudnetworkservicesduetoitssimplicity,效率和concurrencyFeatures.1)installgromtheofficialwebsitealwebsiteandverifywith'.2)

Golang vs.C:性能和速度比較 Golang vs.C:性能和速度比較 Apr 21, 2025 am 12:13 AM

Golang適合快速開發和並發場景,C 適用於需要極致性能和低級控制的場景。 1)Golang通過垃圾回收和並發機制提升性能,適合高並發Web服務開發。 2)C 通過手動內存管理和編譯器優化達到極致性能,適用於嵌入式系統開發。

Golang vs. Python:主要差異和相似之處 Golang vs. Python:主要差異和相似之處 Apr 17, 2025 am 12:15 AM

Golang和Python各有优势:Golang适合高性能和并发编程,Python适用于数据科学和Web开发。Golang以其并发模型和高效性能著称,Python则以简洁语法和丰富库生态系统著称。

Golang和C:性能的權衡 Golang和C:性能的權衡 Apr 17, 2025 am 12:18 AM

Golang和C 在性能上的差異主要體現在內存管理、編譯優化和運行時效率等方面。 1)Golang的垃圾回收機制方便但可能影響性能,2)C 的手動內存管理和編譯器優化在遞歸計算中表現更為高效。

表演競賽:Golang vs.C 表演競賽:Golang vs.C Apr 16, 2025 am 12:07 AM

Golang和C 在性能競賽中的表現各有優勢:1)Golang適合高並發和快速開發,2)C 提供更高性能和細粒度控制。選擇應基於項目需求和團隊技術棧。

Golang vs. Python:利弊 Golang vs. Python:利弊 Apr 21, 2025 am 12:17 AM

Golangisidealforbuildingscalablesystemsduetoitsefficiencyandconcurrency,whilePythonexcelsinquickscriptinganddataanalysisduetoitssimplicityandvastecosystem.Golang'sdesignencouragesclean,readablecodeanditsgoroutinesenableefficientconcurrentoperations,t

See all articles