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
上一篇 Nov 25, 2025 05:00
下一篇 Nov 25, 2025 03:00

Related Posts

  • In-depth Understanding of ES6 002 [Study Notes]

    Strings and Regular Expressions. Strings and Regular Expressions. JavaScript strings have always been built based on 16-bit character encoding (UTF-16). Each 16-bit sequence is a code unit, representing a character. String properties and methods like `length` and `charAt()` are all constructed based on these code units. The goal of Unicode is to provide a globally unique identifier for every character in the world. If we limit the character length to 16 bits, the number of code points will not...

    Personal Mar 8, 2025
    1.8K00
  • From 0 to 1: Implementing Micro-frontend Architecture 001 [Study Notes]

    Micro-frontends, JS isolation, CSS isolation, element isolation, lifecycle, preloading, data communication, application navigation, multi-level nesting. Note: This uses Mermaid's flowchart syntax, which is supported by Markdown renderers such as Typora, VitePress, and some Git platforms. Retained: Host application main-vue3; child applications: child-nuxt2-home, child-vue2-job, child-vu...

    Apr 20, 2025
    1.5K00
  • TS Everest 001 [Study Notes]

    Course Outline: Set up a TypeScript development environment. Master TypeScript's basic, union, and intersection types. Understand the purpose and usage of type assertions in detail. Master type declaration methods for functions and classes in TypeScript. Master the purpose and definition of type aliases and interfaces. Master the application scenarios of generics and apply them proficiently. Flexibly apply conditional types, mapped types, and built-in types. Create and use custom types. Understand the concepts of namespaces and modules, and how to use...

    Personal Mar 27, 2025
    1.5K00
  • [Opening]

    I am Walker, born in the early 1980s, a journeyer through code and life. A full-stack development engineer, I navigate the boundaries between front-end and back-end, dedicated to the intersection of technology and art. Code is the language with which I weave dreams; projects are the canvas on which I paint the future. Amidst the rhythmic tapping of the keyboard, I explore the endless possibilities of technology, allowing inspiration to bloom eternally within the code. An avid coffee enthusiast, I am captivated by the poetry and ritual of every pour-over. In the rich aroma and subtle bitterness of coffee, I find focus and inspiration, mirroring my pursuit of excellence and balance in the world of development. Cycling...

    Feb 6, 2025 Personal
    2.2K00
  • In-depth Understanding of ES6 008 [Study Notes]

    Iterators (Iterator) and Generators (Generator) are new features indispensable for efficient data processing. You will also find iterators present in other language features: the new for-of loop, the spread operator (...), and even asynchronous programming can use iterators. An iterator is a special object that has proprietary interfaces specifically designed for the iteration process. All iterator objects have a next() method, and each call returns a result pair...

    Personal Mar 8, 2025
    1.1K00
EN
简体中文 繁體中文 English
欢迎🌹 Coding never stops, keep learning! 💡💻 光临🌹