36 lines
567 B
Go
36 lines
567 B
Go
package memory
|
|
|
|
import "sync"
|
|
|
|
type Memory struct {
|
|
passwords map[string]struct{}
|
|
mu sync.RWMutex
|
|
}
|
|
|
|
func New() *Memory {
|
|
mem := Memory{
|
|
passwords: make(map[string]struct{}, 16),
|
|
mu: sync.RWMutex{},
|
|
}
|
|
return &mem
|
|
}
|
|
|
|
func (m *Memory) SavePassword(password string) error {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
|
|
m.passwords[password] = struct{}{}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Memory) PasswordExists(password string) (bool, error) {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
|
|
if _, ok := m.passwords[password]; ok {
|
|
return true, nil
|
|
}
|
|
return false, nil
|
|
}
|