Go Engineer System Course 005 [Learning Notes]

For microservice development, create a microservice project where all project microservices will reside. Create `joyshop_srv`. We need to create user login and registration services, so we will create another directory `user_srv` under the project directory, along with `user_srv/global` (for global object creation and initialization), `user_srv/handler` (for business logic code), `user_srv/model` (for user-related models), `user_srv/pro...`

Microservice Development

Create a microservice project. All project microservices will reside within this project. Create joyshop_srv. Since we are not creating a user login and registration service, we will create another directory under the project directory:
user_srv and user_srv/global (global object creation and initialization)
user_srv/handler (business logic code)
user_srv/model (user-related models)
user_srv/proto (user-related models)
main.go service startup file

We use MD5 encryption for passwords.

1. Message Digest Algorithm 5 (MD5) Information Digest Algorithm

MD5 is a common hashing algorithm with the following main characteristics:

  1. Compressibility
    For data of any length, the calculated MD5 value will always have a fixed length.
  2. Ease of Computation
    It is very easy to compute the MD5 value from the original data.
  3. Modification Resistance
    Any modification to the original data, even a single byte, will result in a significantly different MD5 value.
  4. Strong Collision Resistance
    It is extremely difficult to find two different pieces of data that produce the same MD5 value.
  5. Irreversibility
    It is irreversible; the original data cannot be recovered from an MD5 value.

MD5 Salt Encryption

1. Purpose of Salting

To enhance the security of MD5 encryption and prevent rainbow table attacks, a "salt" value is typically added to the original data before MD5 encryption.

2. Salting Methods

  1. Combine by generating a random number and an MD5-generated string
  2. Concatenate the randomly generated salt value with the original password before performing MD5 encryption.
  3. E.g.: md5( password + salt )
  4. Store both MD5 value and salt value in the database
  5. During registration: Generate a salt, compute the salted MD5, and store both in the database.
  6. During verification: Retrieve the salt, re-encrypt, and compare the MD5 values.
// 设置加密参数
options := &password.Options{
 SaltLen:      16,
 Iterations:   100,
 KeyLen:       32,
 HashFunction: sha512.New,
}

// 1. 加密
salt, encodedPwd := password.Encode("your_password", options)
final := fmt.Sprintf("$pbkdf2-sha512$%s$%s", salt, encodedPwd)

// 2. 拆分(模拟从数据库读取)
parts := strings.Split(final, "$")
saltFromDb := parts[2]
hashFromDb := parts[3]

// 3. 验证
ok := password.Verify("your_password", saltFromDb, hashFromDb, options)
fmt.Println("验证是否通过:", ok)

主题测试文章,只做测试使用。发布者:Walker,转转请注明出处:https://walker-learn.xyz/archives/4779

(0)
Walker的头像Walker
上一篇 Mar 10, 2026 00:00
下一篇 Mar 8, 2026 15:40

Related Posts

  • Go Engineering Comprehensive Course 001 [Study Notes]

    Transitioning: Reasons for a rapid, systematic transition to Go engineering:
    To improve CRUD operations.
    To gain experience with self-developed frameworks.
    For colleagues aiming to deepen technical expertise, specializing and refining requirements.
    To advance engineering practices, developing good coding standards and management capabilities.

    The Importance of Engineering

    Expectations for Senior Developers:
    Good code standards.
    Deep understanding of underlying principles.
    Familiarity with architecture.
    Familiarity with K8s basic architecture.
    Expanding knowledge breadth and depth, and a standardized development system.

    Four Major Stages:
    Go language fundamentals.
    Microservice development (e-commerce project practical experience).
    Self-developed microservices.
    Self-developed, then re...

    Personal Nov 25, 2025
    35700
  • In-depth Understanding of ES6 004 [Study Notes]

    Extending object functionality
    Ordinary objects: objects that possess all default internal behaviors of a JavaScript object.
    Exotic objects: objects that possess certain internal behaviors that deviate from the default.
    Standard objects: objects defined in the ES6 specification, such as Array/Date.
    Built-in objects: objects that exist in the JavaScript execution environment when the script begins execution; all standard objects are built-in objects.
    Object literal syntax extensions:
    Shorthand for property initializers: when an object's property has the same name as a local variable, there's no need to write the colon and value.
    Shorthand syntax for object methods...

    Personal Mar 8, 2025
    1.3K00
  • In-depth Understanding of ES6 001 [Study Notes]

    Block-Level Scope Binding
    Previously, `var` variable declarations, regardless of where they were declared, were considered to be declared at the top of their scope. Since functions are first-class citizens, the typical order was `function functionName()`, followed by `var variable`.

    Block-Level Declarations
    Block-level declarations are used to declare variables that cannot be accessed outside the scope of a specified block. Block-level scope exists in:
    - Inside functions
    - Within blocks (the region between `{` and `}`)

    Temporal Dead Zone
    When the JavaScript engine scans code and finds variable declarations, it either hoists them to the top of the scope...

    Personal Mar 8, 2025
    1.7K00
  • In-depth Understanding of ES6 005 [Study Notes]

    Destructuring: Making data access more convenient. If you declare variables using `var`, `let`, or `const` with destructuring, you must provide an initializer (i.e., the value on the right side of the equals sign). The following will cause an error:
    // Syntax error `var {tyep,name}`
    // Syntax error `let {type,name}`
    // Syntax error `const {type,name}`
    To assign values to already declared variables using destructuring, consider the following:
    `let node = { type:&qu...`

    Personal Mar 8, 2025
    1.3K00
  • Go Engineering Systematic Course 003 [Study Notes]

    grpc grpc grpc-go grpc seamlessly integrates protobuf protobuf. For those of you accustomed to using JSON and XML data storage formats, I believe most have never heard of Protocol Buffer. Protocol Buffer is actually a lightweight & efficient structured data storage format developed by Google, and its performance is truly much, much stronger than JSON and XML! protobuf…

    Personal Nov 25, 2025
    25300
EN
简体中文 繁體中文 English