Add password encoding utility and update forms to use encoded passwords for secure data transmission. Enhance axios request interceptor to handle FormData content type correctly.
This commit is contained in:
41
src/utils/passwordCrypto.ts
Normal file
41
src/utils/passwordCrypto.ts
Normal file
@ -0,0 +1,41 @@
|
||||
// Parola transport kodlamasi.
|
||||
// Parolalarin istek govdesinde DUZ METIN gorunmesini engellemek icin Base64 ile kodlanir.
|
||||
// Backend "b64:" on ekini gorunce cozer. (Not: Bu HTTPS/TLS'in yerini tutmaz, ek bir gizleme katmanidir.)
|
||||
|
||||
const PREFIX = 'b64:'
|
||||
|
||||
/**
|
||||
* Verilen parolayi UTF-8 guvenli sekilde Base64'e kodlar ve "b64:" on eki ekler.
|
||||
* Bos/null/undefined degerler oldugu gibi (bos string) donulur.
|
||||
*/
|
||||
export function encodePassword(value: string | null | undefined): string {
|
||||
if (value === null || value === undefined || value === '') return ''
|
||||
|
||||
const bytes = new TextEncoder().encode(String(value))
|
||||
let binary = ''
|
||||
bytes.forEach((b) => {
|
||||
binary += String.fromCharCode(b)
|
||||
})
|
||||
|
||||
return PREFIX + btoa(binary)
|
||||
}
|
||||
|
||||
/**
|
||||
* Verilen nesnenin sig kopyasini olusturur ve belirtilen alanlari encode eder.
|
||||
* Reactive store nesnelerini bozmamak icin daima yeni bir nesne doner.
|
||||
*/
|
||||
export function withEncodedPasswords<T extends Record<string, any>>(
|
||||
data: T,
|
||||
fields: string[]
|
||||
): T {
|
||||
const clone: Record<string, any> = { ...data }
|
||||
|
||||
fields.forEach((field) => {
|
||||
const current = clone[field]
|
||||
if (current !== null && current !== undefined && current !== '') {
|
||||
clone[field] = encodePassword(current)
|
||||
}
|
||||
})
|
||||
|
||||
return clone as T
|
||||
}
|
||||
Reference in New Issue
Block a user