Storing user and password in a database

I am creating a software with user + password. After autentification, the user can access some semi public services, but also encrypt some files that only the user can access.

The user must be stored as is, without modification, if possible. After auth, the user and the password are kept in memory as long as the software is running (i don't know if that's okay either).

The question is how should i store this user + password combination in a potentially unsecure database?

I don't really understand what should i expose.

Let's say I create an enhanced key like this:

salt = random 32 characters string (is it okay?)
key = hash(usr password + salt)
for 1 to 65000 do
  key = hash(key + usr password + salt)

Should I store the [plaintext user], [the enhanced key] and [the salt] in the database ?

Also, what should I use to encrypt (with AES or Blowfish) some files using a new password everytime ? Должен ли я сгенерировать новую соль и создать новый расширенный ключ, используя (пароль, хранящийся в памяти программы + соль)? И в этом случае, если я сохраню зашифрованный файл в базе данных, мне, вероятно, следует хранить только соль. База данных такая же, как и в том месте, где я храню комбинацию пользователя и пароля.

Файл можно расшифровать, только если кто-то может сгенерировать ключ, но он не знает пароля. Верно?

Я использую Python с PyCrypto, но это не очень важно, общий пример подойдет. I have read a few similar questions, but they are not very explicit.

Thank you very very much!

10
задан Oz123 6 August 2014 в 08:10
поделиться